alex
2013-02-07 12:48:02 UTC
Hi all,
I sent this exact same mail to haskell-cafe last year, but didn't find
my answer, and still have the same problem. I am now returning to this
code, and thought someone here might have some advice before I take a
brute-force approach:
A while ago I made an unusual visual front-end for Haskell:
https://github.com/yaxu/texture
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
working.
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
though.
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
this, e.g.:
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!
Best wishes
alex
I sent this exact same mail to haskell-cafe last year, but didn't find
my answer, and still have the same problem. I am now returning to this
code, and thought someone here might have some advice before I take a
brute-force approach:
A while ago I made an unusual visual front-end for Haskell:
https://github.com/yaxu/texture
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
working.
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
though.
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
this, e.g.:
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!
Best wishes
alex