[Haskell-beginners] pattern match vs. pure function

Bastian Erdnüß earthnut at web.de
Tue Oct 19 19:23:49 EDT 2010


Suppose I would want to write a function rmap that acts like

  rmap [f,g,h] x == [f x, g x, h x]

Do I gain any advantage or disadvantage (beside readability) from using

  rmap = flip $ map . flip id

over

  rmap []     _ = []
  rmap (f:fs) x = f x : rmap fs x

?

I could imagine Haskell can optimize the first version better since it refers to the built in map function.  But beside that, does Haskell struggle with the combinatory stuff in the first version?  Or does it get optimized away?  And how "expensive" are pattern matches on the other side, anyway?

Thanks for reading,
Bastian



More information about the Beginners mailing list