|
![](/i/fill.gif) |
Almost every programming language has them. Functions that don't do
anything useful, or functions that you should "never" use.
(For example, there seem to be a few C functions related to I/O which
you probably shouldn't *ever* use - unless you enjoy buffer overflows.)
What useless functions does your favourit language have?
For Haskell, I'd like to nominate the following function:
fix :: (x -> x) -> x
fix f = let x = f x in x
This perplexing little gizmo takes a function and passes that function
as an argument to itself. It is the Haskell implementation of the Y
combinator from the lambda calculus.
The lambda calculus does not support named functions, so at first it
appears to be impossible to write recursive functions. However, the Y
combinator makes it possible - a hugely important theoretical result.
However, this isn't the lambda calculus. This is Haskell. If you want
recursion, just *ask* for recursion! In truth, the only real "use" for
this function is in baffling newbies with incantations such as
fix ((1:) . scanl (+) 1)
If you can figure out what the hell that does without using Google or a
Haskell interpretter, I'll be pretty impressed.
Code geekhood factor? Massive.
Code maintainability factor? Tiny.
Really, apart from scaring newbies, this function serves no useful purpose.
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
![](/i/fill.gif) |