[Haskell-cafe] Re: DDC compiler and effects; better than Haskell?

Heinrich Apfelmus apfelmus at quantentunnel.de
Thu Aug 13 05:06:51 EDT 2009

Russell O'Connor wrote:
> Peter Verswyvelen wrote:
>> I kind of agree with the DDC authors here; in Haskell as soon as a
>> function has a side effect, and you want to pass that function to a
>> pure higher order function, you're stuck, you need to pick the monadic
>> version of the higher order function, if it exists. So Haskell doesn't
>> really solve the modularity problem, you need two versions of each
>> higher order function really,
> Actually you need five versions: The pure version, the pre-order
> traversal, the post-order traversal, the in-order traversal, and the
> reverse in-order traversal.  And that is just looking at syntax.  If you
> care about your semantics you could potentially have more (or less).

Exactly! There is no unique choice for the order of effects when lifting
a pure function to an effectful one.

For instance, here two different versions of an effectful  map :

   mapM f []     = return []
   mapM f (x:xs) = do
       y  <- f x
       ys <- mapM f xs
       return (y:ys)

   mapM2 f []     = return []
   mapM2 f (x:xs) = do
       ys <- mapM2 f xs
       y  <- f x
       return (y:ys)

Which one will the DCC compiler chose, given

   map f []     = []
   map f (x:xs) = f x : map f xs

? Whenever I write a pure higher order function, I'd also have to
document the order of effects.



More information about the Haskell-Cafe mailing list