]> Git — Sourcephile - comptalang.git/blob - lcc/Hcompta/LCC/Sym/IO.hs
Gather into Writeable instances.
[comptalang.git] / lcc / Hcompta / LCC / Sym / IO.hs
1 {-# LANGUAGE UndecidableInstances #-}
2 {-# OPTIONS_GHC -fno-warn-orphans #-}
3 -- | Symantic for the Input/Output.
4 module Hcompta.LCC.Sym.IO where
5
6 import Control.Applicative (Applicative(..))
7 import Data.Eq (Eq)
8 import Data.Foldable (concat)
9 import Data.Function (($), (.))
10 import Data.Functor (Functor(..), (<$>))
11 import Data.Maybe (Maybe(..))
12 import Data.Type.Equality ((:~:)(Refl))
13 import System.IO (IO)
14 import Text.Show (Show(..))
15 import qualified Data.Text as Text
16 import qualified Prelude ()
17
18 import Language.Symantic.Grammar
19 import Language.Symantic
20 import Language.Symantic.Lib (a0, tyIO)
21
22 import Hcompta.LCC.IO (PathFile(..), FromFile)
23 import Hcompta.LCC.Sym.FileSystem (tyPathFile)
24 import qualified Hcompta.LCC.IO as LCC
25
26 -- * Class 'Sym_FromFile'
27 type instance Sym FromFile = Sym_FromFile
28 class Sym_FromFile term where
29 fromFile :: FromFile a => term PathFile -> term (IO a)
30 default fromFile :: Sym_FromFile (UnT term) => Trans term => FromFile a => term PathFile -> term (IO a)
31 fromFile = trans1 fromFile
32
33 instance Sym_FromFile Eval where
34 fromFile = eval1 LCC.fromFile
35 instance Sym_FromFile View where
36 fromFile = view1 "fromFile"
37 instance (Sym_FromFile r1, Sym_FromFile r2) => Sym_FromFile (Dup r1 r2) where
38 fromFile = dup1 @Sym_FromFile fromFile
39 instance (Sym_FromFile term, Sym_Lambda term) => Sym_FromFile (BetaT term)
40
41 instance FixityOf FromFile
42 instance NameTyOf FromFile where
43 nameTyOf _c = ["IO"] `Mod` "FromFile"
44 instance ClassInstancesFor FromFile
45 instance TypeInstancesFor FromFile
46 instance Gram_Term_AtomsFor src ss g FromFile
47 instance (Source src, SymInj ss FromFile) => ModuleFor src ss FromFile where
48 moduleFor = ["IO"] `moduleWhere`
49 [ "fromFile" := teIO_fromFile
50 ]
51
52 tyFromFile :: Source src => Type src vs a -> Type src vs (FromFile a)
53 tyFromFile a = tyConstLen @(K FromFile) @FromFile (lenVars a) `tyApp` a
54
55 teIO_fromFile :: TermDef FromFile '[Proxy a] (FromFile a #> (PathFile -> IO a))
56 teIO_fromFile = Term (tyFromFile a0) (tyPathFile ~> tyIO a0) (teSym @FromFile (lam1 fromFile))