Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What does the `forall a -> b` syntax mean?

In GHCi, the kind of FUN is displayed like this:

λ> :k FUN
FUN :: forall (n :: Multiplicity) -> * -> * -> *

At first, I thought this was a roundabout way of saying

FUN :: Multiplicity -> * -> * -> *

but it turns out Template Haskell has a separate constructor for this form: ForallVisT. I can’t find any documentation on it, and I have no idea how to even begin experimenting with it in a meaningful way.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What does this syntax mean? How does forall a -> b differ from a "normal" forall a. a -> b?

>Solution :

forall a -> _ is used when the result type depends on an explicit argument.

-- type NonDep :: Type -> Type; argument is explicit
data NonDep (x :: Type) :: Type
-- type ImpDep :: forall a. Maybe a -> Type; first argument is implicit and dependent
data ImpDep (x :: Maybe a) :: Type
-- so if you want an explicit and dependent argument...
-- type ExpDep :: forall (a :: Type) -> Maybe a -> Type
data ExpDep (a :: Type) (x :: Maybe a) :: Type

It is odd that FUN‘s type has forall (m :: Multiplicity) -> and not Multiplicity -> as the following arguments (two implicit RuntimeReps and two TYPEs) do not depend on it, but such is the weirdness that surrounds GHC primitives.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading