Suppose I have a function: funcmap :: a->b->c can I use type synonyms to describe a new type like this: Type Funcmap = a->b>c ? it will give a syntax error message: syntax error in input (unexpected '->'), does anyone know how to define this Funcmap type? rui ---------------------------------------- This mail sent through www.mywaterloo.ca
rui yang wrote:
Suppose I have a function:
funcmap :: a->b->c
can I use type synonyms to describe a new type like this: Type Funcmap = a->b>c ?
First, it's 'type' not 'Type'. Second, you want '->' not '>'. Third, all type variables in the RHS must be on the LHS. So, we get type Funcmap a b c = a->b->c
Thanks. What I really want to know is: How to describe a new type (Funcmap) which is itself a function type like a->b-
c so that I can use this new type in other functions? for example, I can define some other functions like:
theta :: Functionmap -> d ->e minus :: Funcmap ->...... I can put all the things there like : theta :: (a->b->c)->d->e but sometimes it's not convenient to do so. rui 引用 Lennart Augustsson <lennart@augustsson.net>:
rui yang wrote:
Suppose I have a function:
funcmap :: a->b->c
can I use type synonyms to describe a new type like this: Type Funcmap = a->b>c ?
First, it's 'type' not 'Type'. Second, you want '->' not '>'. Third, all type variables in the RHS must be on the LHS. So, we get
type Funcmap a b c = a->b->c
---------------------------------------- This mail sent through www.mywaterloo.ca
It depends what sort of polymorphism you want theta to have. If your function types involve concrete types you could write something like type IntMap = Int -> Bool -> String and then say theta :: IntMap -> Int -> String If you want the argument function to be completely polymorphic you can say type FunMap = forall a b c . a -> b -> c But then you couldn't use functions of type IntMap because they are not completely polymorphic. If you want the type variables to be bound in the theta type the only option is what Lennart suggests, type Funcmap a b c = a -> b -> c theta :: Funcmap a b c -> d -> e Trying this out: type Intmap = Int -> Bool -> String type Funcmp1 = forall a b c . a -> b -> c type Funcmp2 a b c = a -> b -> c f1 :: Intmap -> a -> b f2 :: Funcmp1 -> a -> b f3 :: Funcmp2 a b c -> d -> e (f1,f2,f3) = undefined We see the types we can get: *Main> :t f1 f1 :: forall b a. (Int -> Bool -> String) -> a -> b *Main> :t f2 f2 :: forall b a. (forall a1 b1 c. a1 -> b1 -> c) -> a -> b *Main> :t f3 f3 :: forall e d c b a. (a -> b -> c) -> d -> e The IRC channel is pretty good for this sort of question and might have a better turnaround time that the list. Brandon On Wed, 26 Nov 2003, rui yang wrote:
Thanks. What I really want to know is: How to describe a new type (Funcmap) which is itself a function type like a->b-
c so that I can use this new type in other functions? for example, I can define some other functions like:
theta :: Functionmap -> d ->e
minus :: Funcmap ->......
I can put all the things there like : theta :: (a->b->c)->d->e but sometimes it's not convenient to do so.
rui
引用 Lennart Augustsson <lennart@augustsson.net>:
rui yang wrote:
Suppose I have a function:
funcmap :: a->b->c
can I use type synonyms to describe a new type like this: Type Funcmap = a->b>c ?
First, it's 'type' not 'Type'. Second, you want '->' not '>'. Third, all type variables in the RHS must be on the LHS. So, we get
type Funcmap a b c = a->b->c
---------------------------------------- This mail sent through www.mywaterloo.ca _______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
participants (3)
-
Brandon Michael Moore -
Lennart Augustsson -
rui yang