Commit 6c7a5c0c authored by Krzysztof Gogolewski's avatar Krzysztof Gogolewski Committed by Marge Bot

Minor comments, update linear types docs

- Update comments: placeHolderTypeTc no longer exists
  "another level check problem" was a temporary comment from linear types
- Use Mult type synonym (reported in #18676)
- Mention multiplicity-polymorphic fields in linear types docs
parent ee5dcdf9
...@@ -423,7 +423,7 @@ funTyConName = mkPrimTyConName (fsLit "FUN") funTyConKey funTyCon ...@@ -423,7 +423,7 @@ funTyConName = mkPrimTyConName (fsLit "FUN") funTyConKey funTyCon
-- @ -- @
-- type Arr :: forall (rep1 :: RuntimeRep) (rep2 :: RuntimeRep). -- type Arr :: forall (rep1 :: RuntimeRep) (rep2 :: RuntimeRep).
-- TYPE rep1 -> TYPE rep2 -> Type -- TYPE rep1 -> TYPE rep2 -> Type
-- type Arr = FUN -- type Arr = FUN 'Many
-- @ -- @
-- --
funTyCon :: TyCon funTyCon :: TyCon
......
...@@ -1119,14 +1119,14 @@ In the compiler we maintain the invariant that all saturated applications of ...@@ -1119,14 +1119,14 @@ In the compiler we maintain the invariant that all saturated applications of
See #11714. See #11714.
-} -}
splitFunTy :: Type -> (Type, Type, Type) splitFunTy :: Type -> (Mult, Type, Type)
-- ^ Attempts to extract the argument and result types from a type, and -- ^ Attempts to extract the multiplicity, argument and result types from a type,
-- panics if that is not possible. See also 'splitFunTy_maybe' -- and panics if that is not possible. See also 'splitFunTy_maybe'
splitFunTy = expectJust "splitFunTy" . splitFunTy_maybe splitFunTy = expectJust "splitFunTy" . splitFunTy_maybe
{-# INLINE splitFunTy_maybe #-} {-# INLINE splitFunTy_maybe #-}
splitFunTy_maybe :: Type -> Maybe (Type, Type, Type) splitFunTy_maybe :: Type -> Maybe (Mult, Type, Type)
-- ^ Attempts to extract the argument and result types from a type -- ^ Attempts to extract the multiplicity, argument and result types from a type
splitFunTy_maybe ty splitFunTy_maybe ty
| FunTy _ w arg res <- coreFullView ty = Just (w, arg, res) | FunTy _ w arg res <- coreFullView ty = Just (w, arg, res)
| otherwise = Nothing | otherwise = Nothing
......
...@@ -351,9 +351,10 @@ mkPsBindStmt pat body = BindStmt noExtField pat body ...@@ -351,9 +351,10 @@ mkPsBindStmt pat body = BindStmt noExtField pat body
mkRnBindStmt pat body = BindStmt (XBindStmtRn { xbsrn_bindOp = noSyntaxExpr, xbsrn_failOp = Nothing }) pat body mkRnBindStmt pat body = BindStmt (XBindStmtRn { xbsrn_bindOp = noSyntaxExpr, xbsrn_failOp = Nothing }) pat body
mkTcBindStmt pat body = BindStmt (XBindStmtTc { xbstc_bindOp = noSyntaxExpr, mkTcBindStmt pat body = BindStmt (XBindStmtTc { xbstc_bindOp = noSyntaxExpr,
xbstc_boundResultType = unitTy, xbstc_boundResultType = unitTy,
-- unitTy is a dummy value
-- can't panic here: it's forced during zonking
xbstc_boundResultMult = Many, xbstc_boundResultMult = Many,
xbstc_failOp = Nothing }) pat body xbstc_failOp = Nothing }) pat body
-- don't use placeHolderTypeTc above, because that panics during zonking
emptyRecStmt' :: forall idL idR body. IsPass idR emptyRecStmt' :: forall idL idR body. IsPass idR
=> XRecStmt (GhcPass idL) (GhcPass idR) body => XRecStmt (GhcPass idL) (GhcPass idR) body
......
...@@ -999,7 +999,6 @@ writeMetaTyVarRef tyvar ref ty ...@@ -999,7 +999,6 @@ writeMetaTyVarRef tyvar ref ty
-- Check for level OK -- Check for level OK
-- See Note [Level check when unifying] -- See Note [Level check when unifying]
; MASSERT2( level_check_ok, level_check_msg ) ; MASSERT2( level_check_ok, level_check_msg )
-- another level check problem, see #97
-- Check Kinds ok -- Check Kinds ok
; MASSERT2( kind_check_ok, kind_msg ) ; MASSERT2( kind_check_ok, kind_msg )
......
...@@ -101,13 +101,23 @@ Whether a data constructor field is linear or not can be customized using the GA ...@@ -101,13 +101,23 @@ Whether a data constructor field is linear or not can be customized using the GA
:: ::
data T2 a b c where data T2 a b c where
MkT2 :: a -> b %1 -> c %1 -> T2 a b -- Note unrestricted arrow in the first argument MkT2 :: a -> b %1 -> c %1 -> T2 a b c -- Note unrestricted arrow in the first argument
the value ``MkT2 x y z`` can be constructed only if ``x`` is the value ``MkT2 x y z`` can be constructed only if ``x`` is
unrestricted. On the other hand, a linear function which is matching unrestricted. On the other hand, a linear function which is matching
on ``MkT2 x y z`` must consume ``y`` and ``z`` exactly once, but there on ``MkT2 x y z`` must consume ``y`` and ``z`` exactly once, but there
is no restriction on ``x``. is no restriction on ``x``.
It is also possible to define a multiplicity-polymorphic field:
::
data T3 a m where
MkT3 :: a %m -> T3 a m
While linear fields are generalized (``MkT1 :: forall {m} a. a %m -> T1 a``
in the previous example), multiplicity-polymorphic fields are not;
it is not possible to directly use ``MkT3`` as a function ``a -> T3 a 'One``.
If :extension:`LinearTypes` is disabled, all fields are considered to be linear If :extension:`LinearTypes` is disabled, all fields are considered to be linear
fields, including GADT fields defined with the ``->`` arrow. fields, including GADT fields defined with the ``->`` arrow.
...@@ -143,9 +153,9 @@ missing pieces. ...@@ -143,9 +153,9 @@ missing pieces.
have success using it, or you may not. Expect it to be really unreliable. have success using it, or you may not. Expect it to be really unreliable.
- There is currently no support for multiplicity annotations such as - There is currently no support for multiplicity annotations such as
``x :: a %p``, ``\(x :: a %p) -> ...``. ``x :: a %p``, ``\(x :: a %p) -> ...``.
- All ``case``, ``let`` and ``where`` statements consume their - All ``case`` expressions consume their scrutinee ``Many`` times.
right-hand side, or scrutiny, ``Many`` times. That is, the following All ``let`` and ``where`` statements consume their right hand side
will not type check: ``Many`` times. That is, the following will not type check:
:: ::
......
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