For the record, all of these compile with -O to exactly the same code!
> reMatr1 f m = Matr (f (unMatr m))
> reMatr2 f m = Matr $ f $ unMatr m
> reMatr3 f m = Matr . f . unMatr $ m
> reMatr4 f = Matr . f . unMatr
> reMatr5 f = Matr . (flip (.) unMatr) f
> reMatr6 = (Matr .) . (. unMatr)
And that code is the same as what reMatr1 compiles to with no optimization!
Under no optimization, they all compile to direct implementations of their
approach - and hence, reMatr1 is the most efficient. The others must wend
through quite a number of library functions to do their work.
Since there is no real efficiency issue (surely matrix manipulation code will
be compiled -O for actual use), the only reason I can see to choose one of
these over the other is how it conveys the intention from one programmer to the
next. (Or one's self six months later...) In which case seems to me that
reMatr4 most cleanly encapsulates the programmer's intention. Of course, I've
had some Haskell experience and I get the idiom - to someone less versed in
Haskell, reMatr1 is probably the clearest - to someone with much Haskell
experience, perhaps reMatr6, though it just looks "clever" to me, rather than
clear.
I'm curious why the original poster was motivated to pursue pointfree style to
the point of no explicit arguments?
- Mark
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe