[Haskell-cafe] Stacked return
Nickolay Kudasov
nickolay.kudasov at gmail.com
Sat Nov 23 17:49:58 UTC 2013
You could perhaps write MyWierdMonadT and MyAnotherMonadT.
Also, probably layers package [1] is related to what you ask.
But if you actually want arbitrary nested monads like m1 (m2 (m3 (m4 a))),
there's no simple way.
Consider Maybe [MyType Int]. MyType may have or may not have a
Monadinstance. Even more: it can have instance in one module, but not
have in
another. But suppose MyType has a Num instance. Then how this should
work: return
2 :: Maybe [MyType Int]? Should 2 be of type Int or MyType Int?
Note that you can make an instance Num a => Num [a] which makes sense
(lists as polynoms). So the same question arises even for Maybe [Int].
If you **really want to do it** (which I doubt), you can use TH (do
determine how many return's to use, though it's ambiguous anyway).
[1]
http://hackage.haskell.org/package/layers-0.1/docs/Documentation-Layers-Overview.html
2013/11/23 Dmitry Bogatov <KAction at gnu.org>
>
> > Perhaps you just want monad transformers [1, 2]. If you're not familiar
> > with them, you should probably read [3].
> >
> > With transformers you'd be able to do this (and more):
> >
> > $ return 2 :: IO Int
> > $ return 2 :: ListT Maybe Int -- this works like Maybe [Int]
> > $ return 2 :: MaybeT [] Int -- this works like [Maybe Int]
>
> In fact, I read and used transformers a bit. If I understand correctly,
> I can only do such things for monads, supported by transformers. So,
>
> I cant get (return 2) :: MyWierdMonad (MyAnotherMonad 2)
>
> Yes, I know, it have little practical use, but I am insterested about
> teoretical part of question, magic of ghc.
>
> --
> Best regards, Dmitry Bogatov <KAction at gnu.org>,
> Free Software supporter and netiquette guardian.
> git clone git://kaction.name/rc-files.git --depth 1
> GPG: 54B7F00D
> Html mail and proprietary format attachments are forwarded to /dev/null.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20131123/0acbb4cd/attachment.html>
More information about the Haskell-Cafe
mailing list