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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
--- Types for representing ICurry programs
--- @author Marc Andre Wittorf

module ICurry.Types where

import FlatCurry.Types

--- An ICurry qualified name
type IQName = (String, String) -- ModuleName.LocalName

--- An ICurry arity
type IArity = Int

--- An ICurry variable (numerical index)
type IVarIndex = Int

--- An ICurry type variable (numerical index)
type ITVarIndex = Int

--- An ICurry assignment
type IAssign = (IVarIndex, IExpr) -- Variable = Expression

--- A Literal
--- @cons IInt   an integer literal
--- @cons IChar  a char literal
--- @cons IFloat a float literal
data ILiteral
  = IInt
      Int             -- the integer value
  | IChar
      Char            -- the char value
  | IFloat
      Float           -- the float value
  deriving (Show, Read)

--- An ICurry module
data IProg
  = IProg
      String          -- module name
      [String]        -- imports
      [IDataType]     -- declared data types
      [IFunction]     -- declared functions
  deriving (Show, Read)

--- An ICurry visibility
--- @cons Public  Visible and usable from other modules
--- @cons Private Invisible and not usable from other modules
data IVisibility
  = Public
  | Private
  deriving (Show, Read)

--- An ICurry data type
type IDataType = (
      IQName,         -- the data type's name
      IVisibility,    -- if this data type can be used from other modules
      [ITVarIndex],   -- type variables the type is parameterized over
      [IConstructor]) -- all possible constructors

--- An ICurry constructor
data IConstructor
  = IConstructor
      IQName          -- the constructor's name
      IVisibility     -- if this constructor can be used from other modules
      [ITExpr]        -- one type expression for each argument
  deriving (Show, Read)

--- An ICurry type expression
--- @cons ITVar  a type argument
--- @cons ITFunc a functional type
--- @cons ITCons a type application
data ITExpr
  = ITVar
      ITVarIndex      -- the type variable
  | ITFunc
      ITExpr          -- domain type
      ITExpr          -- range type
  | ITCons
      IQName          -- the type's name that is applied
      [ITExpr]        -- the arguments
  deriving (Show, Read)

--- An ICurry function
data IFunction
  = IFunction
      IQName          -- the function's name
      IVisibility     -- if this function can be used from other modules
      IFuncBody       -- what the function does
  deriving (Show, Read)

--- An ICurry function's behavior
--- @cons IExternal the function is externally defined
--- @cons IFuncBody the function is defined here
data IFuncBody
  = IExternal
      IArity          -- the function's arity
      String          -- the function's external name
  | IFuncBody
      [IVarIndex]     -- the function's arguments
      IBlock          -- the function's actual behavior
  deriving (Show, Read)

--- An ICurry block
--- @cons ISimpleBlock   unconditional evaluation
--- @cons ICaseConsBlock conditional evaluation over constructor terms
--- @cons ICaseLitBlock  conditional evaluation over literals
data IBlock
  = ISimpleBlock
      [IAssign]       -- assignments to local variables
      IExpr           -- the return expression
  | ICaseConsBlock
      [IAssign]       -- assignments to local variables
      IVarIndex       -- the variable to differentiate by
      [IConsBranch]   -- the possible branches
  | ICaseLitBlock
      [IAssign]       -- assignments to local variables
      IVarIndex       -- the variable to differentiate by
      [ILitBranch]    -- the possible branches
  deriving (Show, Read)

--- An ICurry branch over constructors
data IConsBranch
  = IConsBranch
      IQName          -- the constructor to match this branch
      [IVarIndex]     -- variable bindings
      IBlock          -- what happens if this branch is taken
  deriving (Show, Read)

--- An ICurry branch over literals
data ILitBranch
  = ILitBranch
      ILiteral        -- the literal to match this branch
      IBlock          -- what happens if this branch is taken
  deriving (Show, Read)

--- An ICurry expression
--- @cons IVar   a variable
--- @cons ILit   a literal
--- @cons IFCall a function call
--- @cons ICCall a constructor call
--- @cons IOr    a non-deterministic choice
data IExpr
  = IVar
      IVarIndex       -- the variable
  | ILit
      ILiteral        -- the literal's value
  | IFCall
      IQName          -- the function's name
      [IExpr]         -- the arguments
  | ICCall
      IQName          -- the constructor's name
      [IExpr]         -- the arguments
  | IOr
      [IExpr]         -- the possibilities
  deriving (Show, Read)

-- This is not part of ICurry format
-- It is needed to convert Typed FlatCurry to ICurry
--- A mapping from functions to its signature and a number of type variables it
--- needs to be completely defined
type NeededMapping = (
      QName,           -- a function's name
        (TypeExpr,     -- the function's signature
         [TVarIndex])) -- type variables (relating to the signature) which must
                       -- be specified