[Haskell-cafe] Tips for converting Prolog to typeclasses?

Greg Buchholz haskell at sleepingsquirrel.org
Thu Jun 1 11:12:06 EDT 2006


Robert Dockins wrote:
> 
> To make this work, you're going to have to convince the compiler to accept 
> "overlapping instances" and then make sure they don't overlap :) In the 
> second instance, what you really want to say is "instance c [a] c, only where 
> c is not an application of (->)".  As I recall, there is a way to express 
> such type equality/unequality using typeclasses, but I don't remember how to 
> do it offhand.

    Now that I think about it more, I see what you are saying.  And I
think we can be a little more general than "c is not an application of
(->)".  A better statement might be "c is not a function application
which takes an 'a' as the first argument".  That should allow us to have
a function of type Int->Int->Double->String return a function
Double->String when applied to a list of Int's.  So in Prolog...

:- op(1000,xfy,=>).

app(A=>B,[A],C) :- app(B,[A],C).
app(C,[A],C) :- not(isfuncwithhead(C,A)).

isfuncwithhead(A=>B,A).

...Now I just need to figure out how to represent "not" without "cut".
I'll take a look at what Oleg has done.

Thanks,

Greg Buchholz


More information about the Haskell-Cafe mailing list