-
Notifications
You must be signed in to change notification settings - Fork 1
/
monadic.go
69 lines (53 loc) · 1.28 KB
/
monadic.go
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
package prism
import (
"fmt"
"github.com/sundown/solution/palisade"
)
type MonadicFunction struct {
Name Ident
OmegaType Type
Returns Type
PreBody *[]palisade.Expression
Body []Expression
Attribute Attribute
}
func (MonadicFunction) Arity() int {
return 1
}
type MonadicApplication struct {
Operator MonadicFunction
Operand Expression
}
// Type property for interface
func (f MonadicFunction) Type() Type {
return f.Returns
}
// Type property for interface
func (m MonadicApplication) Type() Type {
return m.Operator.Type()
}
// String function for interface
func (f MonadicFunction) String() (s string) {
s += f.Name.String() + " " + f.OmegaType.String() + " → " + f.Returns.String() + " {\n"
if f.Body != nil {
for _, p := range f.Body {
s += " " + p.String() + "\n"
}
} else if f.PreBody != nil {
fmt.Println("PREBODY")
}
return s + "}\n"
}
// String function for interface
func (m MonadicApplication) String() string {
return m.Operator.Name.String() + " " + m.Operand.String()
}
func (m MonadicFunction) Ident() Ident {
return m.Name
}
func (d MonadicFunction) Attrs() Attribute {
return d.Attribute
}
func (f MonadicFunction) LLVMise() string {
return f.Name.Package + "." + f.Name.Name + "_" + f.OmegaType.String() + "." + f.Returns.String()
}