[Haskell-cafe] Re: Seeking advice about monadic traversal
functions
Martijn van Steenbergen
martijn at van.steenbergen.nl
Fri Apr 2 14:26:24 EDT 2010
On 3/31/10 12:44, Heinrich Apfelmus wrote:
> go Next (Single x t1) = liftM (Single x) (rewrite f t1)
> go Next (Fork t1 t2 ) = liftM2 Fork (rewrite f t1)
> (rewrite f t2)
>
> In particular, liftM and liftM2 make it apparent that we're just
> wrapping the result in a constructor.
A small remark: I prefer using applicative notation for this:
> go Next (Single x t1) = Single x <$> rewrite f t1
> go Next (Fork t1 t2 ) = Fork <$> rewrite f t1 <*> rewrite f t2
Martijn.
More information about the Haskell-Cafe
mailing list