mirror of
https://github.com/Lysxia/first-class-families.git
synced 2024-09-11 19:47:12 +03:00
Remove deprecated Guarded, Guard(:=), and Otherwise
This commit is contained in:
parent
dec9b0f2a2
commit
b6428eec3f
@ -104,12 +104,6 @@ module Fcf
|
||||
, type (&&)
|
||||
, Not
|
||||
|
||||
-- *** Multi-way if
|
||||
|
||||
, Guarded
|
||||
, Guard((:=))
|
||||
, Otherwise
|
||||
|
||||
-- ** Case splitting
|
||||
|
||||
, Case
|
||||
|
@ -15,17 +15,9 @@ module Fcf.Data.Bool
|
||||
, type (||)
|
||||
, type (&&)
|
||||
, Not
|
||||
|
||||
-- *** Multi-way if
|
||||
|
||||
, Guarded
|
||||
, Guard((:=))
|
||||
, Otherwise
|
||||
) where
|
||||
|
||||
import Fcf.Core
|
||||
import Fcf.Combinators (ConstFn)
|
||||
import Fcf.Utils
|
||||
|
||||
-- | N.B.: The order of the two branches is the opposite of "if":
|
||||
-- @UnBool ifFalse ifTrue bool@.
|
||||
@ -58,32 +50,3 @@ type instance Eval (a && 'True) = a
|
||||
data Not :: Bool -> Exp Bool
|
||||
type instance Eval (Not 'True) = 'False
|
||||
type instance Eval (Not 'False) = 'True
|
||||
|
||||
-- | A conditional choosing the first branch whose guard @a -> 'Exp' 'Bool'@
|
||||
-- accepts a given value @a@.
|
||||
--
|
||||
-- === Example
|
||||
--
|
||||
-- @
|
||||
-- type UnitPrefix n = 'Eval' ('Guarded' n
|
||||
-- '[ 'TyEq' 0 \'':=' 'Pure' \"\"
|
||||
-- , 'TyEq' 1 \'':=' 'Pure' \"deci\"
|
||||
-- , 'TyEq' 2 \'':=' 'Pure' \"hecto\"
|
||||
-- , 'TyEq' 3 \'':=' 'Pure' \"kilo\"
|
||||
-- , 'TyEq' 6 \'':=' 'Pure' \"mega\"
|
||||
-- , 'TyEq' 9 \'':=' 'Pure' \"giga\"
|
||||
-- , 'Otherwise' \'':=' 'Error' "Something else"
|
||||
-- ])
|
||||
-- @
|
||||
data Guarded :: a -> [Guard (a -> Exp Bool) (Exp b)] -> Exp b
|
||||
type instance Eval (Guarded x ((p ':= y) ': ys)) =
|
||||
Eval (If (Eval (p x)) y (Guarded x ys))
|
||||
{-# DEPRECATED Guarded "Use 'Case' instead" #-}
|
||||
|
||||
-- | A fancy-looking pair type to use with 'Guarded'.
|
||||
data Guard a b = a := b
|
||||
infixr 0 :=
|
||||
|
||||
-- | A catch-all guard for 'Guarded'.
|
||||
type Otherwise = ConstFn 'True
|
||||
|
||||
|
20
test/test.hs
20
test/test.hs
@ -4,20 +4,9 @@
|
||||
TypeOperators #-}
|
||||
|
||||
import Data.Type.Equality ((:~:)(Refl))
|
||||
import GHC.TypeLits (Nat)
|
||||
import Fcf
|
||||
|
||||
type UnitPrefix (n :: Nat) = Eval (Guarded n
|
||||
[ TyEq 0 ':= Pure ""
|
||||
, TyEq 1 ':= Pure "deci"
|
||||
, TyEq 2 ':= Pure "hecto"
|
||||
, TyEq 3 ':= Pure "kilo"
|
||||
, TyEq 6 ':= Pure "mega"
|
||||
, TyEq 9 ':= Pure "giga"
|
||||
, Otherwise ':= Error "Something else"
|
||||
])
|
||||
|
||||
type UnitPrefix' = Case
|
||||
type UnitPrefix = Case
|
||||
[ 0 --> ""
|
||||
, 1 --> "deci"
|
||||
, 2 --> "hecto"
|
||||
@ -29,11 +18,8 @@ type UnitPrefix' = Case
|
||||
|
||||
-- Compile-time tests
|
||||
|
||||
_ = Refl :: UnitPrefix 0 :~: ""
|
||||
_ = Refl :: UnitPrefix 9 :~: "giga"
|
||||
|
||||
_ = Refl :: Eval (UnitPrefix' 0) :~: ""
|
||||
_ = Refl :: Eval (UnitPrefix' 3) :~: "kilo"
|
||||
_ = Refl :: Eval (UnitPrefix 0) :~: ""
|
||||
_ = Refl :: Eval (UnitPrefix 3) :~: "kilo"
|
||||
|
||||
-- Dummy
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user