16 Sep
2001
16 Sep
'01
8:28 a.m.
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"
9114
Age (days ago)
9114
Last active (days ago)
0 comments
1 participants
participants (1)
-
Saswat Anand