[Haskell-cafe] testing if values can be applied to polymorphic functions
alex at slab.org
Mon Oct 22 11:24:50 CEST 2012
A while ago I made an unusual visual front-end for Haskell:
It applies functions that are both proximal in Euclidean space, and
type-compatible. It 'compiles' to Haskell, piped into ghci, but I
(probably unwisely) wrote it in C, and ended up having to implement
some crazed version of the Haskell type system there to get it
Now I have idea for making this more interesting and practical (for
live music-making, if nothing else), and would like to re-write it all
in Haskell. Testing type compatibility of expressions is foxing me
For example, say I have (++) and [1,2,3]. I then want to see if a
value of type (Num a => [a]) can be applied to a function of type ([a]
-> [a] -> [a]). I've been looking at Data.Typeable.funResultTy to do
funResultTy (typeOf ((++) :: [a] -> [a] -> [a])) (typeOf ([1,2,3] ::
Num a => [a]))
But I get this:
Ambiguous type variable `a0' in the constraint:
(Typeable a0) arising from a use of `typeOf'
Being a bit more specific doesn't help:
funResultTy (typeOf ((++) :: Typeable a => [a] -> [a] -> [a])) (typeOf
([1,2,3] :: (Typeable a, Num a) => [a]))
I guess funResultTy doesn't work when polymorphism is involved..
Perhaps I could just use the ghc-as-a-library stuff to parse and
typecheck code - would that be the way forward?
Any pointers much appreciated!
More information about the Haskell-Cafe