Hi there,
is there a simple way to carry out the following type of conversion?
Suppose I have a list (finite) of (value,image) pairs such as:
list = [(0,1),(1,0)]
From this I want to generate a function
f 0 = 1
f 1 = 0
Is there a way to do this? Note, I don't want to define a function
that
Use an array. Don't remember for sure, but I think something like
q = array (0, max (map fst list)) list
f = (q!!)
will probably work.
On Fri, May 24, 2002, Carl McTague wrote:
Hi there,
is there a simple way to carry out the following type of conversion?
Suppose I have a list (finite)
If you can live with f's domain being ordered, I'd probably use something
like f = lookupWithDefaultFM (listToFM list) (-1) importing FiniteMap from
ghc's libraries. HTH.
-- Mark
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]