Discussion:
[haskell-art] testing if values can be applied to polymorphic functions
alex
2013-02-07 12:48:02 UTC
Permalink
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
Henning Thielemann
2013-02-07 15:08:15 UTC
Permalink
Post by alex
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.
Rohan Drape
2013-02-22 03:49:55 UTC
Permalink
hello alex,

sorry slow reply, it's summer here...
Post by alex
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
typeable won't work because it examines values, and
you're wanting to check the composition of type
signatures.

if you need ghc-as-a-library it may be better to start
there, however you can do what you want using
haskell-src-ext and HTE.

in the attached, mT infers a type for e3, and mT' rejects e5 saying:

Missing the instance declarations: IsIn "Num" [TCon "Char" Star],...

i'm curious to see how texture turns out!

best,
rohan

ps. HTE is at https://github.com/shayan-najd/HTE

pps. HTE does compile against base=4.6.0.0 if you edit HTE.cabal

Continue reading on narkive:
Search results for '[haskell-art] testing if values can be applied to polymorphic functions' (Questions and Answers)
4
replies
acessing cached pages?
started 2006-07-07 05:56:14 UTC
computers & internet
Loading...