Type Problem
Saswat Anand
saswatan@comp.nus.edu.sg
Sun, 16 Sep 2001 16:28:01 +0800 (GMT-8)
Hi,
I am wondering how can I pass an overloaded function as a parameter
to another function. Consider the following example. I want to tell the
compiler that the argument `fun' in `trickyFun' definition is always
either ord' or chr', and hence it can find the correct overloaded version
in both the cases (1) & (2).
Thanks,
Saswat
class X a where
ord' :: a -> Int
chr' :: a -> Char
instance X Int where
ord' = id
chr' = chr
instance X Char where
ord' = ord
chr' = id
trickyFun fun = let x = fun (2::Int) -----------(1)
y = fun 'c' -----------(2)
in "tricky"