[Haskell] Newbie Question about Types

David Greenberg greenberg.d at gmail.com
Fri Aug 27 14:57:31 EDT 2004


I very recently just came to Haskell from the Java and Perl worlds, so
my understanding of Haskell's type system is still a little vague. 
The tutorial and Google didn't seem to have an answer to my question,
so I am hoping someone here might be able to help me.  I am writing
some code comparable to the following:

class Fooable a where
     foo1 :: a -> a -> a
     foo2 :: a -> a -> a

type MyType a = String -> a

data (Fooable (MyType a)) => AnotherType a = 
     AnotherType {str :: String, myval :: (MyType a)}
instance (Fooable (MyType a)) => Fooable (AnotherType a) where
     (AnotherType s1 m1) `foo1` (AnotherType s2 m2) = 
          AnotherType "dummy string" (m1 `foo1` m2)

The trick here is I want to be able to pass a value of type MyType to
the AnotherType constructor without making MyType directly an instance
of Fooable.  In other words, I want some sort of sub-type of MyType to
be an instance of Fooable.  That way I can use it in the constructor
of AnotherType.

I understand that type inference might make a lot of this easier, but
I am trying to make a very strict API out of my module(s), and feel
that relying on inference at this stage could become buggy.

Thanks in advance for any help that you all can give me.


More information about the Haskell mailing list