a type question

Brandon Michael Moore brandon at its.caltech.edu
Wed Nov 26 18:43:26 EST 2003


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 =3D 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 =3D 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 =3D a -> b -> c
theta :: Funcmap a b c -> d -> e

Trying this out:

type Intmap =3D Int -> Bool -> String
type Funcmp1 =3D forall a b c . a -> b -> c
type Funcmp2 a b c =3D a -> b -> c

f1 :: Intmap -> a -> b
f2 :: Funcmp1 -> a -> b
f3 :: Funcmp2 a b c -> d -> e
(f1,f2,f3) =3D 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
>
>
>
> =D2=FD=D3=C3 Lennart Augustsson <lennart at 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  =3D 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
> >
> > =09type Funcmap a b c =3D a->b->c
> >
>
>
>
>
> ----------------------------------------
> This mail sent through www.mywaterloo.ca
> _______________________________________________
> Haskell mailing list
> Haskell at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
>
>



More information about the Haskell mailing list