Skip to content

Commit 5737ffc

Browse files
Anton ChaynikovAnton-Latukha
authored andcommitted
Make typeFun total
1 parent 0e13db9 commit 5737ffc

File tree

2 files changed

+27
-28
lines changed

2 files changed

+27
-28
lines changed

src/Nix/Type/Infer.hs

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -706,8 +706,9 @@ unops :: Type -> NUnaryOp -> [Constraint]
706706
unops u1 op =
707707
[ EqConst u1
708708
(case op of
709-
NNot -> typeFun [typeBool , typeBool ]
710-
NNeg -> TMany [typeFun [typeInt, typeInt], typeFun [typeFloat, typeFloat]]
709+
NNot -> typeFun $ typeBool :| [typeBool]
710+
NNeg -> TMany [ typeFun $ typeInt :| [typeInt]
711+
, typeFun $ typeFloat :| [typeFloat] ]
711712
)
712713
]
713714

@@ -727,46 +728,46 @@ binops u1 op =
727728

728729
where
729730

730-
gate = eqCnst [typeBool, typeBool, typeBool]
731-
concatenation = eqCnst [typeList, typeList, typeList]
731+
gate = eqCnst $ typeBool :| [typeBool, typeBool]
732+
concatenation = eqCnst $ typeList :| [typeList, typeList]
732733

733-
eqCnst l = [EqConst u1 $ typeFun l]
734+
eqCnst ne = [EqConst u1 $ typeFun ne]
734735

735736
inequality =
736737
eqCnstMtx
737-
[ [typeInt , typeInt , typeBool]
738-
, [typeFloat, typeFloat, typeBool]
739-
, [typeInt , typeFloat, typeBool]
740-
, [typeFloat, typeInt , typeBool]
738+
[ typeInt :| [typeInt , typeBool]
739+
, typeFloat :| [typeFloat, typeBool]
740+
, typeInt :| [typeFloat, typeBool]
741+
, typeFloat :| [typeInt , typeBool]
741742
]
742743

743744
arithmetic =
744745
eqCnstMtx
745-
[ [typeInt , typeInt , typeInt ]
746-
, [typeFloat, typeFloat, typeFloat]
747-
, [typeInt , typeFloat, typeFloat]
748-
, [typeFloat, typeInt , typeFloat]
746+
[ typeInt :| [typeInt , typeInt ]
747+
, typeFloat :| [typeFloat, typeFloat]
748+
, typeInt :| [typeFloat, typeFloat]
749+
, typeFloat :| [typeInt , typeFloat]
749750
]
750751

751752
rUnion =
752753
eqCnstMtx
753-
[ [typeSet , typeSet , typeSet]
754-
, [typeSet , typeNull, typeSet]
755-
, [typeNull, typeSet , typeSet]
754+
[ typeSet :| [typeSet , typeSet]
755+
, typeSet :| [typeNull, typeSet]
756+
, typeNull :| [typeSet , typeSet]
756757
]
757758

758759
addition =
759760
eqCnstMtx
760-
[ [typeInt , typeInt , typeInt ]
761-
, [typeFloat , typeFloat , typeFloat ]
762-
, [typeInt , typeFloat , typeFloat ]
763-
, [typeFloat , typeInt , typeFloat ]
764-
, [typeString, typeString, typeString]
765-
, [typePath , typePath , typePath ]
766-
, [typeString, typeString, typePath ]
761+
[ typeInt :| [typeInt , typeInt ]
762+
, typeFloat :| [typeFloat , typeFloat ]
763+
, typeInt :| [typeFloat , typeFloat ]
764+
, typeFloat :| [typeInt , typeFloat ]
765+
, typeString :| [typeString, typeString]
766+
, typePath :| [typePath , typePath ]
767+
, typeString :| [typeString, typePath ]
767768
]
768769

769-
eqCnstMtx mtx = [EqConst u1 $ TMany $ typeFun <$> mtx]
770+
eqCnstMtx mtx = [EqConst u1 $ TMany $ map typeFun mtx]
770771

771772
liftInfer :: Monad m => m a -> InferT s m a
772773
liftInfer = InferT . lift . lift . lift

src/Nix/Type/Type.hs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
module Nix.Type.Type where
55

66
import Prelude hiding ( Type, TVar )
7-
import Data.Foldable ( foldr1 )
87
import Nix.Expr.Types
98

109
-- | Hindrey-Milner type interface
@@ -39,9 +38,8 @@ typeSet = TSet mempty mempty
3938
typeList :: Type
4039
typeList = TList mempty
4140

42-
typeFun :: [Type] -> Type
43-
-- Please, replace with safe analog to `foldr1`
44-
typeFun = foldr1 (:~>)
41+
typeFun :: NonEmpty Type -> Type
42+
typeFun (head_ :| tail_) = foldr (:~>) head_ tail_
4543

4644
-- | Concrete types in the Nix type system.
4745
typeInt, typeFloat, typeBool, typeString, typePath, typeNull :: Type

0 commit comments

Comments
 (0)