grammar: rename At -> Sourced
[haskell/symantic.git] / symantic-lib / Language / Symantic / Lib / If.hs
index 4055f32bef8bb0ba60cdfd2c3f371c365435d0b6..d6c13839d5432ecb6baa4652c741babd77b295db 100644 (file)
@@ -3,6 +3,8 @@
 -- | Symantic for @If@.
 module Language.Symantic.Lib.If where
 
+import Data.Bool
+import Data.Function (($))
 import qualified Data.Text as Text
 
 import Language.Symantic
@@ -13,7 +15,7 @@ import Language.Symantic.Lib.Function (a0)
 data If
 
 -- * Class 'Sym_If'
-type instance Sym (Proxy If) = Sym_If
+type instance Sym If = Sym_If
 class Sym_If term where
        if_ :: term Bool -> term a -> term a -> term a
        default if_ :: Sym_If (UnT term) => Trans term => term Bool -> term a -> term a -> term a
@@ -25,7 +27,7 @@ instance Sym_If Eval where
 instance Sym_If View where
        if_ (View cond) (View ok) (View ko) =
                View $ \po v ->
-                       parenInfix po op $
+                       pairIfNeeded pairParen po op $
                        Text.concat
                         [ "if ", cond (op, SideL) v
                         , " then ", ok (op, SideL) v
@@ -38,16 +40,18 @@ instance (Sym_If r1, Sym_If r2) => Sym_If (Dup r1 r2) where
 instance (Sym_If term, Sym_Lambda term) => Sym_If (BetaT term)
 
 -- Typing
+instance NameTyOf If where
+       nameTyOf _c = ["If"] `Mod` "If"
 instance ClassInstancesFor If
 instance TypeInstancesFor If
 
 -- Compiling
-instance Module src ss If
 instance Gram_Term_AtomsFor src ss g If
  -- TODO: some support for if-then-else or ternary (?:) operator
+instance ModuleFor src ss If
 
 -- ** 'Type's
 
 -- ** 'Term's
-teIf_if :: TermDef If '[Proxy a] (Bool -> a -> a -> a)
+teIf_if :: TermDef If '[Proxy a] (() #> (Bool -> a -> a -> a))
 teIf_if = Term noConstraint (tyBool ~> a0 ~> a0 ~> a0) $ teSym @If $ lam3 if_