[Haskell-cafe] constant functions

michael rice nowgate at yahoo.com
Wed Dec 27 21:42:01 EST 2006

I'm trying to learn Haskell and translating some Lisp
functions as exercises.

How would I write a Haskell function named ALWAYS that
behaves like this:

one = always 1
bozo = always "clown"

> map one [2,3,4,5,6]

> one 62

> map bozo [2,3,4,5,6]
["clown","clown" ,"clown", "clown"," clown"]

> bozo 62

i.e. ALWAYS returns a function with a single parameter
that is ignored, returning instead the value given to
ALWAYS when the function was created.

This is what I've been trying:

always :: (a -> a) -> a -> a
always x = (\y -> x)

one = always 1


Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 

More information about the Haskell-Cafe mailing list