[Haskell-beginners] Using a monad function inside the monad transfomer variant
Moritz Tacke
moritz.tacke at gmail.com
Sat Feb 2 18:50:22 UTC 2019
Ok, thank you, I'll try!
Just to understand this: Is this due to a specific reason? Couldn't
the compiler infer from a definition of a RVar that the same function
can also be used in the RVarT situation? It would (somehow) look
cleaner and I do not see any differences in the semantics
On Fri, Feb 1, 2019 at 6:57 PM Seph Shewell Brockway <seph at codex.scot> wrote:
>
> On Fri, Feb 01, 2019 at 03:14:32PM +0100, Moritz Tacke wrote:
> > Hi,
> >
> > I still want to use the functions that return RVars, so eg.
> >
> > rvarDouble :: RVar Double
> >
> > and then the definition of the transformer function would be:
> >
> > someFunction a b =
> > do ...
> > the_double <- rvarDouble
> > ....
> >
> > This does not compile, complaining that;
> >
> > • Couldn't match type ‘Data.Functor.Identity.Identity’ with ‘ST s’
> > Expected type: RVarT (ST s) Double
> > Actual type: RVar Double
> >
> > How can I re-user the RVar function in the RVarT monad transformer?
>
> Your declaration of rvarDouble needs to be polymorphic in the monad:
>
> rvarDouble :: Monad m => RVarT m Double
>
> The crucial observation is that RVar is actually a type synonym for
> RVarT Identity, so the function can still be made to return a plain
> RVar Double, but it can also return an RVarT (ST s) Double, satisfying
> the type-checker in the example that you gave.
>
> --
> Seph Shewell Brockway, BSc MSc (Glas.)
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
More information about the Beginners
mailing list