Howto implement Control.Monad.Zip

38 views
Skip to first unread message

Aidan Delaney

unread,
Oct 8, 2017, 3:09:02 AM10/8/17
to purescript
Dear all,
There are a number of things that I usually use in Haskell, that I can't find in Purescript.  I suspect this is by design and that I'm looking at things the wrong way, in which case I'd appreciate a course correction.

I'd like to use Control.Monad.Zip [1].  It's not in Purescript prelude so I checked pursuit and found `purescript-control`.  Then, stripping out some GHC specific code from the Haskell version, I proceeded to write `Control.MonadZip`.  The Haskell `Monad.Zip` uses tuples, which suggested that I pull in `Data.Tuple` into `purescript-control` to satisfy my `Control.MonadZip`.  This is a problem for many reasons:

  a. it's clear that `purescript-control` has minimal dependencies by design.  Adding a dependency on `purescript-tuples` is bad style.
  b. More importantly, it doesn't work because `purescript-tuples` itself has a circular dependency on `purescript-control`.

So, my question is.  Am I looking at this the wrong way?  Is there already an analog of Control.Monad.Zip that I'm not recognising?  If not, is the best way to implement this to have a `purescript-control-extras` package that contains Control.Monad.Zip and Control.Monad.Fix?  This follows the style of Control.Monad.ST being implemented in `purescript-st`.



-- 
Dr Aidan Delaney

Harry Garrood

unread,
Oct 8, 2017, 9:49:51 AM10/8/17
to pures...@googlegroups.com
Hi Aidan,

I'm not aware of an analog of that type class, and it might simply be
that nobody has wanted it in PureScript yet. What I would suggest in
this case is indeed creating a new package containing the type class(es)
you want. I might suggest something like `purescript-monad-zip` and/or
`purescript-monad-fix` over `purescript-control-extras` so that it's a
little clearer what the package contains, but since it's your own
package it's entirely up to you.

See also https://github.com/zrho/purescript-monad-fix - which looks like
it was written for a previous version of the compiler and probably needs
a small amount of work before it's useful again, but could be a good
starting point.

In general, one possibility in cases where you might want to avoid
incurring a `tuples` dependency is to use a record like { fst :: a, snd
:: b } instead of a tuple, although in this case I think I probably
would go for tuples anyway.

Best
Harry
> --
> You received this message because you are subscribed to the Google Groups
> "purescript" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to purescript+...@googlegroups.com.
> Visit this group at https://groups.google.com/group/purescript.
> For more options, visit https://groups.google.com/d/optout.

msz...@gmail.com

unread,
Oct 8, 2017, 3:02:47 PM10/8/17
to pures...@googlegroups.com
Hi Aidan,

Using tuples will let you express the laws using
`***` which you can find in the purescript-profunctor package:
https://pursuit.purescript.org/packages/purescript-profunctor/3.0.0/docs/Data.Profunctor.Stron
g#v:(***)
And you can use constructor (and type alias as well): `/\` which are in
`Data.Tuple.Nested` - but that's just a syntactic sugar.

Best,
Marcin
signature.asc
Reply all
Reply to author
Forward
0 new messages