[Haskell] type question revisited
Abraham Egnor
abe.egnor at gmail.com
Mon Jun 6 10:12:03 EDT 2005
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) as
> foo :: (a -> String) -> [a] -> [String]
> foo (shw :: t) x =
> let shf :: t
> shf o = shw o
> in map shf x
or equivalently
> foo :: (a -> String) -> [a] -> [String]
> foo (shw :: t -> String) x =
> let shf :: t -> String
> shf o = shw o
> in map shf x
The essential aspect is that the 'a' from the type signature is *not*
in scope for the let-bound type signature; you have to bring the
appropriate variable 't' in by using an in-line type signature for
'shw'.
Abe
On 6/3/05, mv <mv42c at dodo.com.au> wrote:
> 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 the above
> gives
> thise error in hugs:
>
> Use of shf requires at least 1 argument
>
>
>
>
> ____________
> Virus checked by G DATA AntiVirusKit
> Version: AVK 12.0.37 from 06.12.2002
> Virus news: www.antiviruslab.com
>
> _______________________________________________
> Haskell mailing list
> Haskell at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
>
More information about the Haskell
mailing list