~jojo/Carth

ref: ee429e8ba7a4b52a7f638a89e8ca27a92e0c16dd Carth/src/TypeAst.hs -rw-r--r-- 1.0 KiB
ee429e8bJoJo Remove unused definitions 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
-- | This module mostly exists to expost the builtin types via convenient variables,
--   instead of requiring redefinitions or manually typing the strings of TConst's, which
--   would be prone to typo errors.
module TypeAst where

import Data.Word

data TPrim
    = TNat Word32
    | TNatSize
    | TInt Word32
    | TIntSize
    | TF16
    | TF32
    | TF64
    | TF128
    deriving (Show, Eq, Ord)

type TConst t = (String, [t])

class TypeAst t where
    tprim :: TPrim -> t
    tconst :: TConst t -> t
    tfun :: t -> t -> t
    tbox :: t -> t

mainType :: TypeAst t => t
mainType = tIO tUnit

tIO :: TypeAst t => t -> t
tIO a = tconst ("IO", [a])

tByte :: TypeAst t => t
tByte = tprim (TNat 8)

tBox' :: t -> TConst t
tBox' t = ("Box", [t])

tStr' :: TConst t
tStr' = ("Str", [])

tArray :: TypeAst t => t -> t
tArray a = tconst ("Array", [a])

tUnit :: TypeAst t => t
tUnit = tconst tUnit'

tUnit' :: TConst t
tUnit' = ("Unit", [])

tBool :: TypeAst t => t
tBool = tconst ("Bool", [])

tBool' :: TConst t
tBool' = ("Bool", [])