[Haskell-cafe] need help understanding how to specify constraints on monads

Ryan Reich ryan.reich at gmail.com
Fri Jun 29 07:43:23 UTC 2018


On Fri, Jun 29, 2018 at 2:51 AM, Tom Ellis <
tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> wrote:

> On Thu, Jun 28, 2018 at 03:23:18PM -0700, Dennis Raddle wrote:
> > My idea was to create a typeclass, Comp, parameterized on the the
> > composition data structure ('comp'), the data type of a single "move" or
> > step to be added, ('step'), and the type of an evaluation units ('eu').
> >
> > class Comp comp eu step | comp -> eu, comp -> step where
> >   listPossibleSteps :: comp -> [step]
> >   addStep :: comp -> step -> comp
> >   evalComp :: eu -> comp -> comp
>
> Have you considered just making a record?
>
>     data Comp comp eu step = Comp {
>       listPossibleSteps :: comp -> [step],
>       addStep :: comp -> step -> comp,
>       evalComp :: eu -> comp -> comp
>     }
>
> If you make it a class then you end up in the bizarre situation where you
> can only have one collection of functionality for each type `comp`.
>
> Tom



This in turn can be worked around using a newtype wrapper for each
alternate instance you want.  I like this but I understand why it is often
seen as awkward.

Ryan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20180629/c0202806/attachment.html>


More information about the Haskell-Cafe mailing list