Commit c63a4650 authored by owst's avatar owst Committed by Krzysztof Gogolewski
Browse files

Subsume NullaryTypeClasses by MultiParamTypeClasses (#8993)

MPTC now also handles the nullary case
parent fe593349
......@@ -2865,7 +2865,8 @@ xFlags = [
( "FlexibleInstances", Opt_FlexibleInstances, nop ),
( "ConstrainedClassMethods", Opt_ConstrainedClassMethods, nop ),
( "MultiParamTypeClasses", Opt_MultiParamTypeClasses, nop ),
( "NullaryTypeClasses", Opt_NullaryTypeClasses, nop ),
( "NullaryTypeClasses", Opt_NullaryTypeClasses,
deprecatedForExtension "MultiParamTypeClasses" ),
( "FunctionalDependencies", Opt_FunctionalDependencies, nop ),
( "GeneralizedNewtypeDeriving", Opt_GeneralizedNewtypeDeriving, setGenDeriving ),
( "OverlappingInstances", Opt_OverlappingInstances, nop ),
......
......@@ -1578,13 +1578,12 @@ checkValidClass :: Class -> TcM ()
checkValidClass cls
= do { constrained_class_methods <- xoptM Opt_ConstrainedClassMethods
; multi_param_type_classes <- xoptM Opt_MultiParamTypeClasses
; nullary_type_classes <- xoptM Opt_NullaryTypeClasses
; fundep_classes <- xoptM Opt_FunctionalDependencies
-- Check that the class is unary, unless multiparameter or
-- nullary type classes are enabled
; checkTc (nullary_type_classes || notNull tyvars) (nullaryClassErr cls)
; checkTc (multi_param_type_classes || arity <= 1) (classArityErr cls)
-- Check that the class is unary, unless multiparameter type classes
-- are enabled (which allows nullary type classes)
; checkTc (multi_param_type_classes || arity == 1)
(classArityErr arity cls)
; checkTc (fundep_classes || null fundeps) (classFunDepsErr cls)
-- Check the super-classes
......@@ -2054,15 +2053,15 @@ classOpCtxt :: Var -> Type -> SDoc
classOpCtxt sel_id tau = sep [ptext (sLit "When checking the class method:"),
nest 2 (pprPrefixOcc sel_id <+> dcolon <+> ppr tau)]
nullaryClassErr :: Class -> SDoc
nullaryClassErr cls
= vcat [ptext (sLit "No parameters for class") <+> quotes (ppr cls),
parens (ptext (sLit "Use NullaryTypeClasses to allow no-parameter classes"))]
classArityErr :: Class -> SDoc
classArityErr cls
= vcat [ptext (sLit "Too many parameters for class") <+> quotes (ppr cls),
parens (ptext (sLit "Use MultiParamTypeClasses to allow multi-parameter classes"))]
classArityErr :: Int -> Class -> SDoc
classArityErr n cls
| n == 0 = mkErr "No" "no-parameter"
| otherwise = mkErr "Too many" "multi-parameter"
where
mkErr howMany allowWhat =
vcat [ptext (sLit $ howMany ++ " parameters for class") <+> quotes (ppr cls),
parens (ptext (sLit $ "Use MultiParamTypeClasses to allow "
++ allowWhat ++ " classes"))]
classFunDepsErr :: Class -> SDoc
classFunDepsErr cls
......
......@@ -767,11 +767,8 @@ checkValidInstHead ctxt clas cls_args
; checkTc (xopt Opt_FlexibleInstances dflags ||
all tcInstHeadTyAppAllTyVars ty_args)
(instTypeErr clas cls_args head_type_args_tyvars_msg)
; checkTc (xopt Opt_NullaryTypeClasses dflags ||
not (null ty_args))
(instTypeErr clas cls_args head_no_type_msg)
; checkTc (xopt Opt_MultiParamTypeClasses dflags ||
length ty_args <= 1) -- Only count type arguments
length ty_args == 1) -- Only count type arguments
(instTypeErr clas cls_args head_one_type_msg) }
-- May not contain type family applications
......@@ -801,11 +798,7 @@ checkValidInstHead ctxt clas cls_args
head_one_type_msg = parens (
text "Only one type can be given in an instance head." $$
text "Use MultiParamTypeClasses if you want to allow more.")
head_no_type_msg = parens (
text "No parameters in the instance head." $$
text "Use NullaryTypeClasses if you want to allow this.")
text "Use MultiParamTypeClasses if you want to allow more, or zero.")
abstract_class_msg =
text "The class is abstract, manual instances are not permitted."
......
......@@ -1175,6 +1175,7 @@
</row>
<row>
<entry><option>-XNullaryTypeClasses</option></entry>
<entry>Deprecated, does nothing. <link linkend="nullary-type-classes">nullary (no parameter) type classes</link> are now enabled using <option>-XMultiParamTypeClasses</option>.</entry>
<entry>Enable <link linkend="nullary-type-classes">nullary (no parameter) type classes</link>.</entry>
<entry>dynamic</entry>
<entry><option>-XNoNullaryTypeClasses</option></entry>
......
......@@ -4317,7 +4317,9 @@ We use default signatures to simplify generic programming in GHC
<sect3 id="nullary-type-classes">
<title>Nullary type classes</title>
Nullary (no parameter) type classes are enabled with <option>-XNullaryTypeClasses</option>.
Nullary (no parameter) type classes are enabled with
<option>-XMultiTypeClasses</option>; historically, they were enabled with the
(now deprecated) <option>-XNullaryTypeClasses</option>.
Since there are no available parameters, there can be at most one instance
of a nullary class. A nullary type class might be used to document some assumption
in a type signature (such as reliance on the Riemann hypothesis) or add some
......
{-# LANGUAGE NullaryTypeClasses, StandaloneDeriving #-}
{-# LANGUAGE MultiParamTypeClasses, StandaloneDeriving #-}
module T7959 where
class A
......
TcNoNullaryTC.hs:3:1:
No parameters for class ‘A’
(Use NullaryTypeClasses to allow no-parameter classes)
(Use MultiParamTypeClasses to allow no-parameter classes)
In the class declaration for ‘A’
{-# LANGUAGE NullaryTypeClasses #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module TcNullaryTCFail where
class A
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment