Leave a comment

thesz October 29 2008, 22:00:39 UTC
Elegant and nice. Thank you very much.

Reply

ext_72902 November 5 2008, 17:47:35 UTC
Certainly nice, but it can be done in a different way, which seems more elegant for me:
data OrdRest m a where
OrdReturn :: a -> OrdRest m a
OrdBind :: Ord a => m a -> (a -> OrdRest m b) -> OrdRest m b
instance Monad (OrdRest m) where
return = OrdReturn
OrdReturn x >>= f = f x
OrdBind mx g >>= f = OrdBind mx $ \x -> g x >>= f
embed mx = OrdBind mx OrdReturn
unembed (OrdReturn x) = ordReturn x
unembed (OrdBind mx g) = ordBind mx $ unembed . gAnyway, it's kinda pattern, and being such it shows that Haskell isn't powerful enough.

Reply

ext_72902 November 5 2008, 17:49:18 UTC
BTW, types derived for "embed" and "unembed" are
embed :: (Ord a) => m a -> OrdRest m a
unembed :: (OrdMonad m, Ord b) => OrdRest m b -> m b

Reply

hsenag November 5 2008, 18:01:16 UTC
I don't see any particular difference (in terms of elegance or otherwise) between doing the collapsing early or late, but obviously that's a matter of personal taste.

It turns out that it is possible to use associated data types (GHC 6.8+) to abstract over this pattern: http://www.haskell.org/pipermail/haskell-cafe/2008-March/041084.html. I merged this with the above idea to make a general restricted monad library: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/rmonad, but didn't get round to blogging about it.

Reply

ext_72902 November 5 2008, 18:58:47 UTC
> I don't see any particular difference (in terms of elegance or otherwise) between doing the collapsing early or late, but obviously that's a matter of personal taste.

Me neither, it's only a matter of program length.

> http://www.haskell.org/pipermail/haskell-cafe/2008-March/041084.html

Wow, missed that somehow. Beautiful.

Reply


Leave a comment

Up