[Haskell-beginners] Definition of last: why complicate it?
Kim-Ee Yeoh
ky3 at atamo.com
Sat Apr 5 03:19:03 UTC 2014
On Sat, Apr 5, 2014 at 4:55 AM, Dimitri DeFigueiredo <
defigueiredo at ucdavis.edu> wrote:
> For comparison, could you also translate the inefficient version of plast
> into the case notation you use above?
>
You probably already know this already, but it's worth underscoring for
everyone that it's not the translation into case notation /per se/ that
gives you the incremental performance improvement.
A function definition by parts is syntactic sugar for a single case
expression.
All syntactic sugar, including others like do-notation, where clauses,
etc., gets eliminated at the earliest stages when code is handed off to ghc.
I encourage newcomers to familiarize themselves with desugaring to avoid
unpleasant surprises. The sugared syntax often suggests mystery and magic
when there's really nothing of that sort at all.
Coming back to the topic of function definition by parts, aka piecewise
definition, it appears that at least one reputable school thinks it's
"weird" and "confusing" enough to be warrant a ban in homework:
http://www.reddit.com/r/haskell/comments/223fi4/need_help/cgiywxi
-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140405/1b88dc09/attachment.html>
More information about the Beginners
mailing list