Language extensions
The language features Cupid accepts beyond Haskell 2010. They are
always on, and no option turns them off, except overlapping instances,
which need +o or +O. LANGUAGE pragmas are read as comments, so
code that needs a missing extension usually fails with a syntax or type
error, not a message about the extension.
Each feature is here because the shipped libraries (see The libraries) or packages written for GHC need it, and each is written as GHC writes it; GHC's version is often more general, and the differences are listed under the feature. The exception is restricted type synonyms, Hugs's own, kept from the 2006 release.
Not accepted lists the major features left out and the common GHC extensions that are missing. A GHC extension that neither this page nor Haskell 2010 conformance mentions is not implemented. Why the language is what it is explains how a feature gets in.
Type classes
Flexible contexts
In Haskell 2010 a context constrains type variables, possibly applied to types. In Cupid any type may be constrained, in signatures and in class and instance declarations:
g :: (C [a], D (a -> b)) => [a] -> bFlexible instances
In Haskell 2010 an instance head is a data or newtype constructor
applied to distinct type variables. In Cupid any type may be made an
instance, and a type synonym may stand for it:
instance Show (a -> a) where ...
instance Show (Tree Int) where ...
instance MyClass a where ...
instance C String where ...
type Pair a = (a, a)
instance Swap (Pair a) where ...
With flexible contexts as well, constraint solving is undecidable in
general. Cupid bounds the depth of constraints it will reduce, set by
the -c option (default 40), and reports an error when the bound is
reached. Reaching it usually means the constraints would not have
terminated. GHC instead restricts the form of instances
syntactically.
Overlapping instances
Two instances overlap when a type could match both:
class C a where c :: a
instance C (Bool,a) where ...
instance C (a,Char) where ...
Cupid rejects this:
ERROR "Test.hs":3 - Overlapping instances for class "C"
*** This instance : C (a,Char)
*** Overlaps with : C (Bool,a)
*** Common instance : C (Bool,Char)
With +o, overlap is allowed when one instance type is a substitution
instance of the other and not equal to it:
class C a where toString :: a -> String
instance C [Char] where ...
instance C a => C [a] where ...
For [Char] the first instance is chosen; for [t] with t any
other type, the second. Contexts play no part in the choice.
When t is a type variable, as in
f :: C a => [a] -> String
f xs = toString xs
the choice cannot be made and Cupid rejects the definition. With +O
it is accepted and the more general instance is chosen, which is wrong
if f is later applied to a [Char].
The Prelude avoids this situation for Show by giving the class a
showList method; the same technique often removes the need for
overlap.
Multi-parameter type classes
A class may have more than one parameter, expressing a relation between types:
class Isomorphic a b where
from :: a -> b
to :: b -> a
It may also have none. A zero-parameter class is a named set of values with a single instance, a way to give a program a configuration point:
class Config where
verbose :: Bool
instance Config where
verbose = TrueFunctional dependencies
Multi-parameter classes are often ambiguous. A functional dependency
after a | says that some parameters determine others:
class MyClass a b c | a -> b where ...
There cannot be two instances with the same a and different b, and
the type checker uses that to resolve b once a is known. Several
dependencies may be given, and a dependency may have several
parameters on either side:
class MyClass a b c | a -> b, a -> c where ...
class MyClass a b c | a -> b c where ...
class MyClass a b c | a b -> c where ...
The design is from Type Classes with Functional Dependencies, Mark P. Jones, ESOP 2000.
Quantified types
Rank-2 types
A function argument may be polymorphic if the function's signature
says so with forall:
g :: (forall a. a -> a) -> (Bool, Char)
g f = (f True, f 'a')
Restrictions:
- A function with a polymorphic argument must have an explicit
signature, and its definition must name that argument on the left:
g = undefinedis an error. - A polymorphic argument may only be matched by a variable or a wildcard pattern.
- Such a function must always be applied to its polymorphic argument;
gcannot be used on its own, passed to another function, or defined asmyRunST = runST. WritemyRunST :: (forall s. ST s a) -> aandmyRunST x = runST x; without the signature that is rejected too. - A type variable bound by
forallmust be used in the quantified type. - The rank is at most 2: a polymorphic argument's own arguments must
be monomorphic,
((forall a. a -> a) -> Int) -> Intis an error, and so is a polymorphic type as a type constructor's argument, as in[forall a. a -> a].
runST :: (forall s. ST s a) -> a in Control.Monad.ST has such a
type.
A polymorphic result moves to the front of the signature, so
(forall a. a -> a) -> (forall b. b -> (b, b)) is
forall b. (forall a. a -> a) -> b -> (b, b), as in GHC before 9.0.
A forall may give the variables it binds their kinds,
forall (m :: Type -> Type) a. m a -> m a, where a variable would
otherwise get a kind that is not the one meant.
One exception to the rule that such a function must be applied to its
polymorphic argument: f $ x is checked as f x, as GHC does, so
runST $ do ... is accepted, and so is C $ \x -> ... for a
constructor C with a polymorphic field (see
Polymorphic components). This applies to
the Prelude's $ only, and a type error in f $ x is reported against
f x. Other uses of $ are not affected; map ($ x) fs means what
it always did.
Polymorphic components
A constructor field may be polymorphic:
newtype List a = MkList (forall r. r -> (a -> r -> r) -> r)
newtype NatTrans f g = MkNT (forall a. f a -> g a)
data MonadT m = MkMonad {
my_return :: forall a. a -> m a,
my_bind :: forall a b. m a -> (a -> m b) -> m b }
The constructors then have rank-2 types and must be applied to their polymorphic arguments when used. Record update is not available on records with polymorphic fields.
Polymorphic type synonyms
A type synonym may name a polymorphic type, which is how lens and "Scrap your boilerplate" libraries name theirs:
type Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t
type SimpleLens s a = Lens s s a a
type GenericT = forall a. Data a => a -> a
lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b
over :: ASetter s t a b -> (a -> b) -> s -> t
everywhere :: GenericT -> GenericT
newtype ReifiedLens s a = ReifiedLens { runLens :: SimpleLens s a }
Each use is expanded before type checking, so it is legal where the
written-out expansion would be: as the whole of a signature or its
result, where its forall moves to the front
(lens is Functor f => (s -> a) -> ... -> (a -> f b) -> s -> f t),
as a function argument in a signature, or as a constructor's field.
A polymorphic synonym in a list, in another type constructor or in an
instance head is an error. A synonym whose body uses a polymorphic
synonym, such as SimpleLens, is expanded the same way.
A synonym's argument is expanded where the synonym's body puts it, so
it may be polymorphic if that place allows a polymorphic type, as with
GHC's LiberalTypeSynonyms: given type GenericQ r = forall a. Data a => a -> r, GenericQ GenericT is forall a b. (Data a, Data b) => a -> b -> b. This holds for any synonym, so given type Fun a = a -> Int,
Fun GenericT has a rank-2 argument, while [GenericT] is still an
error.
A synonym's body may have a forall and a context only at its front,
and, unlike GHC with RankNTypes, there is no rank 3 or higher.
Existential quantification
A forall before a constructor quantifies a type variable that does
not appear in the result type:
data Accum a = forall s. MkAccum s (a -> s -> s) (s -> a)
adder = MkAccum 0 (+) id
averager = MkAccum (0,0) (\x (t,n) -> (t+x, n+1)) (uncurry (/))
Matching on MkAccum s add get gives an s of unknown type that can
only be passed to add and get:
runAccum (MkAccum s add get) [] = get s
runAccum (MkAccum s add get) (x:xs) = runAccum (MkAccum (add x s) add get) xs
Existential constructors may not have named fields and their types may
not have a deriving clause, though
standalone deriving can derive for them.
GADT syntax
A data or newtype declaration may list its constructors as
signatures in a where block:
data Shape a where
Circle :: a -> Shape a
Rect :: a -> a -> Shape a
Named :: { label :: String, inner :: Shape a } -> Shape a
Strict :: !Int -> a -> Shape a
Nil, Unit :: Shape a
(:+:) :: Shape a -> Shape a -> Shape a
deriving Show
Each signature means what the equation form would have meant. Its
result must be the type being declared applied to distinct type
variables; those variables are the signature's own and are matched by
position with the ones the head binds, so C :: a -> b -> T b
declares a constructor whose second argument has the type's parameter
and whose first is existential. Any variable not in the result is
existential, and the context of a constructor with such a variable is
packed with the constructor and given back on a match, as for a
forall constructor in the equation form:
data Some where
Some :: Show a => a -> Some
showSome :: Some -> String
showSome (Some x) = show x
The head may give the type's kind instead of naming its parameters,
data Expr :: * -> * where ..., in which case the kind's arguments
bind as many variables as it has arrows (see Kind
signatures). A forall at the front of a
signature is accepted and makes no difference. A newtype in this
syntax has exactly one constructor, with one argument.
Differences from GHC's GADTSyntax and GADTs:
- A constructor whose result refines the type's arguments, such as
IntE :: Int -> Expr Int, is rejected: these are generalised algebraic data types proper, which Cupid does not have. - A context on a constructor constrains the constructor's own arguments, as in the equation form; it cannot be used to refine the result type either.
- The equation form's restrictions carry over: no
derivingclause for a type with an existential constructor, and no selectors on such a constructor. - A context on a constructor with no existential variable,
C :: Show a => a -> T a, loads, but matching onCends inINTERNAL ERROR: leaveScope. So doesderivingforT, as a clause or standalone, and a field onCends inINTERNAL ERROR: typeSel2.
Type operators
A constructor operator, a symbol starting with :, may name a type
constructor or synonym. It is declared with its operands either side,
the first two in parentheses when there are more:
data a :| b = a :| b
data (f :+: g) p = L1 (f p) | R1 (g p)
type a :-> b = a -> b
and used infix in any type, K Int :+: K Bool. The prefix form,
(:+:) f g p, is a syntax error. A type operator is imported and
exported like any type constructor, as (:+:)(..).
Differences from GHC's TypeOperators:
- Fixity declarations do not apply to types. A type operator binds
less tightly than application and more tightly than
->, and groups to the right, soa :+: b :+: cisa :+: (b :+: c). A chain of different operators,a :+: b :*: c, must be parenthesised and is otherwise rejected. A fixity declaration for an operator that is only a type is accepted and has no effect; one for an operator that is also a data constructor applies to the constructor. - A type operator must start with
:; GHC also allows+and the other variable symbols. - A class may not be named by an operator.
Kind signatures
A declaration may say what kind its type constructor or class has. The kind can be written on the variables the declaration binds:
newtype Fix (f :: * -> *) = In (f (Fix f))
class Container (f :: * -> *) where
empty :: f a
or in a standalone signature before or after the declaration, where
the kind of a class ends in Constraint:
type Compose :: (* -> *) -> (* -> *) -> * -> *
newtype Compose f g a = Compose (f (g a))
type Shaped :: (* -> *) -> Constraint
class Shaped f where
shape :: f a -> String
A kind is *, Type, Constraint, or an arrow between kinds, with
parentheses to group. Type and Constraint are names the kind
grammar knows; nothing has to be in scope for them, but
import Data.Kind (Type, Constraint) is accepted so that programs
written for GHC load unchanged. Write * -> * with spaces: *->* is
one operator symbol.
Every kind so declared is unified with the kind that inference would
otherwise start from, and inference then proceeds as usual, so the
signature can only narrow what is inferred. A signature that does
not fit its declaration, for example one with the wrong number of
arrows, is reported against the signature; a declaration whose
constructors use a variable at a kind other than the one given is
reported as the usual kind error at the use. A standalone signature
for a type or class the module does not declare is an error. With
+k, :info shows the kinds.
Differences from GHC's KindSignatures and StandaloneKindSignatures:
- A kind annotation may be written only on the variables that a
data,newtype,typeorclassdeclaration or aforallbinds, not elsewhere inside a type. - A kind has no variables: there is no kind polymorphism.
Data.Kind.Typecannot be written qualified in a kind.
Equality constraints
A context may say that two types are the same:
f :: (a ~ Int) => a -> Int
f x = x + 1
g :: (f a ~ Maybe Int, g ~ (Int -> Bool)) => f a -> g -> Bool
g m p = maybe False p m
Each side of ~ is a type without a function arrow, or any type in
parentheses. A single equality may stand without parentheses,
a ~ [Char] => a -> Int, and an equality may sit beside class
constraints in the same context. An equality may be written in the
context of a type signature, of an expression signature, of a class
method's signature, of a polymorphic argument or field type, and of an
instance declaration.
In a signature the equality is given: the body is checked with the two
sides made one type, so f above is checked at Int -> Int, and the
inferred type must be as general as the declared type read that way.
At a use of f the equality is wanted, and is solved at once by
unifying its sides, so :type f reports Int -> Int; :info f shows
the signature as written. An equality carries no evidence: it is never
a dictionary parameter or argument.
In an instance context an equality lets the head match more than it commits to, and the equality then fixes the rest:
class Describe a where
describe :: a -> String
instance (a ~ Char) => Describe [a] where
describe s = "string " ++ s
describe [] is accepted: the constraint Describe [t] matches the
instance for any t, and the equality makes t Char. A type the
equality cannot make fit, describe [True], is an error, reported at
the instance.
The two sides of an equality must have the same kind. A type variable that occurs only in an equality is not ambiguous, since the other side determines it.
Differences from GHC's TypeFamilies and GADTs, which are where ~
comes from:
- An equality may not appear in the context of a
dataornewtypedeclaration or of one of its constructors, in either syntax: that would refine the result type on a match, which is a generalised algebraic data type, and Cupid does not have those. - An equality may not be a superclass.
- A given equality that cannot hold,
(Int ~ Bool) => ..., is rejected at the signature; GHC accepts the signature and the function is simply uncallable. - An instance whose context has an equality cannot be used by
deriving. - There are no type families, so an equality is never stuck: it is solved, or it is an error, where it arises.
Constraint synonyms
A type synonym may name a constraint:
import GHC.Stack (HasCallStack)
import Data.Kind (Constraint)
type Partial = HasCallStack
type ShowEq a = (Show a, Eq a)
type MonadIOFail m = (MonadIO m, MonadFail m)
type Trivial = (() :: Constraint)
firstRepeat :: ShowEq a => [a] -> String
In a context the synonym stands for its parts: ShowEq a gives what
Show a and Eq a give, and holds wherever they both hold. Its body
is a class constraint, a tuple of them, or anything given the kind
Constraint; the empty constraint must be written (() :: Constraint),
since a bare () is the unit type. A synonym may name another, and
may be exported and imported like a class.
Each synonym is a class of its own, with its body as the superclasses
and one instance, instance (Show a, Eq a) => ShowEq a, which is what
:info shows. It differs from GHC's ConstraintKinds in that:
- The body may not have an equality, since an equality may not be a superclass.
- A synonym must be applied to all its parameters, as a class is.
- Only a synonym's own declaration can give it the kind
Constraint; there are no other types of that kind, so a constraint cannot be a type parameter.
Anonymous type variables
An underscore in a type stands for a fresh type variable:
count :: [_] -> Int
count = length
:type count reports [a] -> Int. Each _ is a different variable,
so _ -> _ is a -> b.
Type annotations in patterns
A pattern may carry a type signature:
f (x :: Int) = fromIntegral x :: Double
A type variable in such an annotation, unless already bound by an enclosing pattern annotation, is bound over the pattern's scope, and type signatures inside that scope refer to it:
sortImage :: Ord b => (a -> b) -> [a] -> [a]
sortImage (f :: a -> b) = sortBy cmp
where
cmp :: a -> a -> Ordering
cmp x y = compare (f x) (f y)
The a in the signature of cmp is the one bound by the pattern.
The signature of sortImage itself is not connected to it: pattern
annotations bind variables in inner signatures, never the other way
round.
Differences from GHC's scoped type variables:
- GHC's pattern-bound type variables may be instantiated; in Cupid they
are rigid, so
g (xs :: [a]) = xs ++ "\n"is rejected. - A
forallin a signature does not scope over the definition: givenf :: forall a. [a] -> [a], anain awheresignature is a new variable, soys :: [a]; ys = xsis rejected. Bind the variable in a pattern annotation instead. - Variables bound in a class or instance head do not scope over the method definitions in Cupid.
- A result type signature on the left of a function definition,
f x :: Int = ..., is accepted and checked like an expression signature on the right-hand side. GHC rejects it.
Tuple sections
A tuple with some components left out is a function of the missing ones, in order:
(,True) -- \x -> (x, True)
(1,,3,) -- \x y -> (1, x, 3, y)
map (,0) xs -- pairs each element with 0
With every component left out, (,,) is the tuple constructor, as
in Haskell 2010. A tuple section is an expression only, not a
pattern. As in GHC, a component given in the section is evaluated
afresh at each application rather than once.
Field puns
In a record pattern, construction or update, a field name on its own
stands for field = field:
data R = R { a :: Int, b :: String }
getA (R {a}) = a
mk a b = R {a, b}Typeable for every type
Every type built from type constructors is an instance of
Data.Typeable's Typeable, as in GHC, without an instance
declaration, so typeOf and cast work on the program's own types and
any type can be made an exception (see
the libraries):
import Data.Typeable
data Color = Red | Green
newtype Wrap f a = Wrap (f a)
-- typeOf (Wrap (Just Red)) ==> Wrap Maybe Color
-- cast Red :: Maybe Color ==> Just Red
The type checker builds the TypeRep from the type's structure when no
instance matches, and reduces Typeable (T a) in an inferred context to
Typeable a. An argument of kind Type is solved as a Typeable
predicate of its own, by an instance if one matches; an argument of
another kind must be built from type constructors, so
Typeable (StateT s m a) holds for m = IO but cannot be solved, or
required, for an unknown m.
deriving Typeable is accepted and does nothing.
Deriving Generic
deriving Generic, with Generic imported from GHC.Generics,
gives a type a representation built from that module's types, so that
a function written once over the representation works for every such
type:
import GHC.Generics
data T a = A Int a | B deriving Generic
class GCount f where
gcount :: f p -> Int
instance GCount U1 where
gcount _ = 0
instance GCount (K1 i c) where
gcount _ = 1
instance (GCount f, GCount g) => GCount (f :+: g) where
gcount (L1 x) = gcount x
gcount (R1 y) = gcount y
instance (GCount f, GCount g) => GCount (f :*: g) where
gcount (x :*: y) = gcount x + gcount y
instance GCount f => GCount (M1 i c f) where
gcount (M1 x) = gcount x
fields :: (Generic a r, GCount r) => a -> Int
fields x = gcount (from x)
fields (A 1 'x') is 2. The representation has the shape GHC
gives it: M1 D around the type, :+: between constructors, M1 C
around each, :*: between fields, M1 S around each, and K1 R
holding the field; U1 for a constructor without fields and V1 for
a type without constructors. Sums and products are balanced.
datatypeName, moduleName, isNewtype, conName, conFixity,
conIsRecord and selName give the metadata. A constructor's
fixity is infix when derived Show would show it infix.
A declaration with no constructors may have a deriving clause, as
Haskell 2010 allows; Generic is the only class that can be derived
for it.
Differences from GHC's DeriveGeneric:
- There are no type families, so the representation is the second
parameter of the class, determined by the first:
class Generic a rep | a -> rep. Where GHC code writes(Generic a, GShow (Rep a)) => ..., write(Generic a r, GShow r) => .... Code that namesRepdoes not load. - There are no type-level strings, so the metadata in a
representation are type indices, not names:
MetaData Tfor the type,MetaCons T nfor its constructors andMetaSel T n mfor their fields, withnandmcounted inZeroandSucc. The metadata classes find the names through a third method ofGeneric,datatypeInfo, whichderivingdefines. Code that uses only the classes is not affected. - The metadata classes' methods take an
M1rather than any type constructor applied to the metadata. Generic1cannot be derived, and the Prelude's own types have noGenericinstances.
Deriving Data
deriving Data, with Data imported from Data.Data, gives a type
the instance that generic programming in the style of "Scrap your
boilerplate" works with, as in GHC:
import Data.Data
data Shape = Circle Double | Rect { width, height :: Double }
deriving Data
-- toConstr (Rect 1 2) ==> Rect
-- constrFields (toConstr (Rect 1 2)) ==> ["width","height"]
-- gmapQ (\d -> typeOf d) (Rect 1 2) ==> [Double,Double]
The data type is named with its module, Main.Shape, and a
constructor whose name begins with : has the fixity Infix.
Deriving strategies and deriving via
A declaration may have several deriving clauses, and a clause may
name how its classes are derived:
newtype Score = Score Int
deriving stock Show -- the standard way, as with no strategy
deriving (Eq, Ord) via Int -- reuse Int's instances
deriving (Semigroup, Monoid) via Sum Int -- reuse Sum Int's
deriving newtype Num -- via the type Score wraps, Int
deriving C via V gives the type the instance of V, reusing its
methods: a newtype constructor does nothing at run time, so a Score
and a Sum Int are the same value and Monoid (Sum Int)'s methods
work on both. deriving newtype C, on a newtype, is deriving C via
the type it wraps. The via type may mention the declaration's type
variables, newtype Opt a = Opt (Maybe a) deriving Eq via Maybe a.
For a class whose parameter is a type constructor, such as Monad,
the instance is for the type without its last parameter:
newtype Parser a = Parser (StateT String Maybe a)
deriving (Functor, Applicative, Monad) via StateT String Maybe
gives Monad Parser. With the newtype strategy, the via type is
what the newtype wraps less those parameters, so
newtype App m a = App (StateT Int m a)
deriving newtype (Functor, Applicative, Monad)
derives them via StateT Int m. What the newtype wraps must end in
the parameters left off, and have them nowhere else.
The instance's context is the one V's instance needs, and its
superclasses are the type's own, so deriving Ord via V needs an
Eq instance for the type as usual.
Two checks keep this safe:
- The type and
Vmust be the same at run time: equal once the newtypes and synonyms at their heads are unwrapped. Anything inside must be equal as written;[Age]and[Int]are not the same here. A newtype applied to fewer than all its parameters unwraps when what it wraps ends in the missing ones: givennewtype Lifting t m a = Lifting (t m a),Lifting t mist m. - The class's methods must not mention a class with functional
dependencies in their contexts, or a type whose constructors hold
class evidence (an existential constructor with a context). Either
could let evidence for
Vpass as evidence for the type, and a dependency then fix a type wrongly.
Differences from GHC's DerivingStrategies, DerivingVia and
GeneralizedNewtypeDeriving:
- There are no roles. The first check is stricter than GHC's
Coerciblebelow the head of the type, and the second is a conservative stand-in for what roles prevent. - In a
derivingclause, only a class of one parameter can be derived via a type; a standalone declaration can derive any class. - A clause cannot use the
anyclassstrategy.
Standalone deriving
A deriving instance declaration asks for an instance away from the
type's declaration, with its context written out:
deriving instance Show a => Show (Tree a)
deriving stock instance Eq Colour
deriving newtype instance Num Age
deriving via (Sum Int) instance Semigroup Score
deriving anyclass instance Describe Colour
deriving via (LiftingAccum MaybeT m) instance
MonadAccum w m => MonadAccum w (MaybeT m)
With no strategy, or stock, the instance's methods are derived as
for a clause, and the head may be any type with constructors,
Show (Tree Int) as well as Show (Tree a). newtype derives via
the type the newtype wraps, and via V via V, with the same two
checks as a deriving clause; the via type stands for the class's last
parameter, so a class of several parameters can be derived too.
anyclass gives an instance with no methods, which then has the class's
defaults.
Nothing is inferred: the instance has exactly the context written,
which must give what the methods need. deriving instance Typeable T
is accepted and does nothing, whatever its strategy, as every type is
Typeable under its own name.
This is how to derive an instance whose context a deriving clause
cannot infer. As in GHC, each constraint in an inferred context may
mention only type variables, with no repeats, as in Show (f a) or
Show (f (g a)); it cannot hold Show (f Int), Show (f a a) or
Show (f (Fix f)). So
data T f = T (f Int) deriving Show
is an error that asks for a standalone declaration, which can be
data T f = T (f Int)
deriving instance Show (f Int) => Show (T f)
Without this rule, inferring the context of
data T f a = T (f a) (T f [a]) would never end, as it would need
Show (f [a]), then Show (f [[a]]), and so on.
Generic cannot be derived this way, since its instance needs the
representation as a second parameter; derive it in the type's
declaration.
Restricted type synonyms
A type synonym may be declared transparent inside the definitions of
named functions and opaque everywhere else, which makes an abstract
type without a newtype or a module boundary:
type Stack a = [a] in emptyStack, push, pop, topOf, isEmpty
emptyStack :: Stack a
emptyStack = []
push :: a -> Stack a -> Stack a
push = (:)
pop :: Stack a -> Stack a
pop (_:xs) = xs
Within emptyStack, push and the other listed functions a Stack a
is a [a]. Elsewhere it is not: emptyStack ++ [1] is a type error,
because Stack a does not match [a]. The list of functions may
carry their signatures instead of naming them:
type Table = [(String, Int)] in
emptyT :: Table,
addT :: String -> Int -> Table -> Table,
findT :: String -> Table -> Maybe Int
The demo demos/Stack.hs uses this. The same effect is available
portably with a newtype or by not exporting a type's constructors.
Not accepted
These parts of GHC's language are not in Cupid, and no option adds
them. A program that uses one of them does not load, except where
ignoring it cannot change what the program means: RULES pragmas are
read as comments, and mask does nothing, since there are no
asynchronous exceptions to hold off. Why the language is what it
is
gives the reasons.
| Feature | Status |
|---|---|
| Type families, open, closed or associated | Not accepted, and not decided: whether they can be added is open |
| GADTs with refined result types | Not accepted: only the syntax is |
Unboxed types and MagicHash | Not accepted |
| Template Haskell | Not accepted |
| Rewrite rules | RULES pragmas are read as comments |
| Linear types | Not accepted |
| STM and asynchronous exceptions | Not accepted. forkIO threads switch only at the primitives of Control.Concurrent, throwTo is absent and mask is a no-op |
These common GHC extensions are not implemented either. Each was tried and fails to load, with a syntax or type error or, for deriving, a message that the class cannot be derived:
| Extension | What happens |
|---|---|
LambdaCase, MultiWayIf, BlockArguments, EmptyCase | Syntax error at \case, if |, a do argument, or case x of {} |
BangPatterns, ViewPatterns, PatternSynonyms, RecordWildCards | f !x = x defines the operator !, so f is undefined, and let !x = e is a syntax error; syntax error at -> in a pattern or ..; pattern P = 1 gives an undefined constructor |
TypeApplications | read @Int gives "Illegal @ in expression" |
InstanceSigs, DefaultSignatures | A signature in an instance, or default in a class, is an error |
DeriveFunctor, DeriveFoldable, DeriveTraversable | "Cannot derive instances of class" |
DataKinds | Syntax error in a kind |
BinaryLiterals | 0b101 reads as 0 b101 |
OverloadedStrings | A string literal always has type String |
See also
- Options for
+o,+Oand-c - The language Cupid accepts