liveBook · Manning

Forall

As explained in Functional Design and Architecture: Examples in Haskell

forall is a Haskell type-level quantifier that introduces a locally scoped universally quantified type variable.

forall introduces a locally scoped, universally quantified type variable. In a GADT constructor, it keeps the result type inside that constructor instead of making one result type govern the entire language. section 6.4.2

A locally typed DSL operation

data LogicControlMethod next = forall a. EvalHdl (Hdl a) (a -> next) | forall a. EvalDeviceControlMethod (DeviceControlMethod a) (a -> next). One script can therefore evaluate an Hdl returning controllers and another returning unit without forcing a common result type.

How Functional Design and Architecture: Examples in Haskell covers it

How deep it goes
Explains constructor scope, continuation typing, and the failure of a globally shared result parameter.
Examples
Uses EvalHdl constructors, mixed-result scripts, and the complete LogicControl definition.
What it assumes
Requires understanding of Haskell type variables and GADTs, with GADT syntax explicitly enabled.
What you can do after
Build GADT constructors whose individual operations may return different types while preserving continuation safety.
How it connects
Connects forall with GADTs, free monads, continuations, and embedded domain-specific languages.

This explainer was generated by Manning's knowledge graph from the text of Functional Design and Architecture: Examples in Haskell. The section links point to the parts of the book it draws on.