Re: [haskell-art] testing if values can be applied to polymorphic functions

2013-02-07 Thread Henning Thielemann


On Thu, 7 Feb 2013, alex wrote:


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]).


That is, you want to do Haskell type checking in Haskell? I do not 
understand how Typeable could help here. If you are happy with a 
simplified Haskell type system you could try the type checker from the 
Helium project. I have also heard that the Haskell suite shall contain a 
type checker.


___
haskell-art mailing list
haskell-art@lurk.org
http://lists.lurk.org/mailman/listinfo/haskell-art


[haskell-art] testing if values can be applied to polymorphic functions

2013-02-07 Thread alex
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:
  http://www.youtube.com/watch?v=5KtFlGEVFGE
  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

___
haskell-art mailing list
haskell-art@lurk.org
http://lists.lurk.org/mailman/listinfo/haskell-art