Your first attempt didn't typecheck simply because
> in return ()
means that the return value of the function is monadic, but you did
not declare as such.
In your second version, the type of shf is *not* a rank-2 type; it's
exactly the same type as shw. This can be expressed (with ghc
extensions)
I answered my own question only to raise another - what I wanted to do is
this
> foo :: (a -> String) -> [a] -> [String]
> foo shw x =
> let
> shf :: ( forall a . a ) -> String
> shf o = shw o
>
> in map shf x
the type of shf is a rank 2 type - but how do you map it ? as
what is the type of 'shf' in
> foo :: (a -> String) -> a -> ()
> foo shw x =
> let
> shf o = shw o
>
> in return ()
for it certainly is not 'shf :: a -> String',
as this explicit signature will not type check ?
Virus checked by G DATA AntiVirusKit
Version: AVK 1
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
t
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
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
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
-
> Hi
> I am new to Haskell and have a question about types.
>
> I have defined a type Type
>
> data Type = D1[Type]
> | D2 String String [Type]
> | D3 String String
> | D4
> |
> | D14
> deriving (Show)
>
> Where D4
Hi
I am new to Haskell and have a question about types.
I have defined a type Type
data Type = D1 [Type]
| D2 String String [Type]
| D3 String String
| D4
|
| D14
deriving (Show)
Where D4 - D14 each have 2-5 Strin
>
> This is a distilled version of a problem that arose in a student's program:
>
> > f :: a -> a
> > f x = g
> >where
> >g :: a
> >g = x
>
> Reading file "[...]":
> Type checking
> ERROR "[...]" (line 5): Inferred type is not general enough
> *** Expression: g
> *** Expected ty
This is a distilled version of a problem that arose in a student's program:
> f :: a -> a
> f x = g
>where
>g :: a
>g = x
Reading file "[...]":
Type checking
ERROR "[...]" (line 5): Inferred type is not general enough
*** Expression: g
*** Expected type : a
*** Inferred type : _2
>I have two functions
>
>> fos:: Num a -> [a] -> [a]
>> fos a x = fos' a 0 x
>
>> fos':: Num a -> a -> [a] -> [a]
>> fos' _ _ [] = []
>> fos' a y1 (x:xs) = y : fos' a y xs
>>where y = a * y1 + x
First of all, I think your type signatures are wrong, unless
nly be along these lines.
Hope this helps
Chris
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]On
> Behalf Of Matthew Donadio
> Sent: Monday, November 09, 1998 2:02 PM
> To: Haskell List
> Subject: Haskel Type Question
>
>
I have two functions
> fos:: Num a -> [a] -> [a]
> fos a x = fos' a 0 x
> fos':: Num a -> a -> [a] -> [a]
> fos' _ _ [] = []
> fos' a y1 (x:xs) = y : fos' a y xs
>where y = a * y1 + x
Why does
> fos -0.5 [ 1, 1, 1, 1 ]
give me
[a] -> b -> [b] -> [b] i
14 matches
Mail list logo