POV-Ray : Newsgroups : povray.off-topic : Most pointless function ever Server Time
7 Sep 2024 05:09:19 EDT (-0400)
  Most pointless function ever (Message 1 to 1 of 1)  
From: Invisible
Subject: Most pointless function ever
Date: 7 Aug 2008 08:31:41
Message: <489aeb2d$1@news.povray.org>
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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.