forall quantifier

Graham Klyne GK@ninebynine.org
Wed, 04 Jun 2003 13:51:13 +0100


I don't properly understand this either, but as it happens I was looking at=
=20
this in the GHC user guide only yesterday...

[[
:
   MkFoo :: forall a. a -> (a -> Bool) -> Foo
   Nil   :: Foo

Notice that the type variable a in the type of MkFoo does not appear in the=
=20
data type itself, which is plain Foo. For example, the following expression=
=20
is fine:

   [MkFoo 3 even, MkFoo 'c' isUpper] :: [Foo]

Here, (MkFoo 3 even) packages an integer with a function even that maps an=
=20
integer to Bool; and MkFoo 'c' isUpper packages a character with a=20
compatible function. These two things are each of type Foo and can be put=20
in a list.
:
]]
--=20
http://www.haskell.org/ghc/docs/latest/html/users_guide/type-extensions.html=
#EXISTENTIAL-QUANTIFICATION

At 15:20 04/06/03 +0200, Ketil Z. Malde wrote:

>Hi,
>
>This is one of those topics everybody else seems to be familiar with,
>but which I don't quite understand, and can't seem to find any good
>information about.
>
>I have a function declared as:
>
>   anova2 :: (Fractional c, Ord b)
>             =3D> [a->b] -> (a->c) -> [a] -> [Anova1 c]
>
>where the first parameter is a list of classifiers.  I could simplify
>it, I guess, to something like
>
>   classify :: Eq b =3D> [a->b] -> [a] -> [[[a]]]
>   classify cs xs =3D ...
>
>where for each classifying function in cs, I would get the xs
>partitioned accordingly.  E.g.
>
>   classify [fst,snd] [(1,0), (1,2), (2,0)]
>
>would yield
>
>   [ [(1,0), (1,2)], [(2,0)] -- classified by `fst`
>   , [(1,0), (2,0)], [(1,2)]] -- classified by `snd`
>
>Now, obviously, the problem is that fst and snd, being passed in a
>list, needs to be of the same type; this complicates classifying a
>list of type [(Int,Bool)], for instance=B9.
>
>I have a vague notion this is solvable using quantifiers (since I
>ever only use Eq operations on the type), but I'm not sure exactly
>how, I can't seem to find a good tutorial, and my Monte-Carlo
>programming approach doesn't seem to be leading anywhere :-)
>
>Can somebody suggest a solution, or a place to look?
>
>-kzm
>
>=B9 I guess I can convert Bool to Int (True->1, False->0), but it's not
>very appealing, IMHO.
>--
>If I haven't seen further, it is by standing in the footprints of giants
>_______________________________________________
>Haskell mailing list
>Haskell@haskell.org
>http://www.haskell.org/mailman/listinfo/haskell

-------------------
Graham Klyne
<GK@NineByNine.org>
PGP: 0FAA 69FF C083 000B A2E9  A131 01B9 1C7A DBCA CB5E