[Haskell-cafe] constant functions

Donald Bruce Stewart dons at cse.unsw.edu.au
Wed Dec 27 23:32:02 EST 2006


nowgate:
> Hi Donald,
> 
> I think you misunderstood what I was asking. There's
> not two cases. Maybe I'm not saying it sufficiently
> well but the function ALWAYS just returns a function
> that always returns the original argument to ALWAYS no
> matter what else you give the resulting function.
> 
> when one is define as follows
> 
>  one = always 1
> 
> then
> 
> > one 4
> 1
> > one "abc"
> 1
> > one (2,3)
> 1
> > one [0,4,8,2]
> 1
> > map one ["one","two","three"]
> [1,1,1]
> 
> The mapping example is just an alternative way of
> illustrating the functionality. No matter what the
> defined function is given it always gives back the
> original value give to ALWAYS.

Ah yes, I must have missed the 'map one' in the original post.
Hence I thought you were looking for different behaviour for lists.

My mistake. Prelude.const is your friend :-)

-- Don


More information about the Haskell-Cafe mailing list