aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-03-29 19:31:45 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-03-29 19:31:45 +0200
commitcb726fac520ed6336610d90af63c61044c51dfee (patch)
tree59868250d0ea008b81e3bbae82bdb8f3c9772ec5
parent5899aa90533584ffb81bec6b5073b203b58a22fb (diff)
Experimental
-rw-r--r--format.go15
-rw-r--r--monad.go15
2 files changed, 23 insertions, 7 deletions
diff --git a/format.go b/format.go
index d635be9..94e21d6 100644
--- a/format.go
+++ b/format.go
@@ -5,13 +5,14 @@ import (
"math"
)
-type S string // string
-type I int64 // int
-type F float64 // float
-type C complex128 // complex
-type A interface{} // any
-type M func(A) A // monad
-type D func(A, A) A // dyad
+type S string // string
+type I int64 // int
+type F float64 // float
+type C complex128 // complex
+type A interface{} // any
+
+type Monad func(complex128) complex128
+type Dyad func(complex128, complex128) complex128
func (s S) String() string {
return string(s)
diff --git a/monad.go b/monad.go
new file mode 100644
index 0000000..14a1d68
--- /dev/null
+++ b/monad.go
@@ -0,0 +1,15 @@
+package main
+
+import "math/cmplx"
+
+var monads = map[rune]Monad{
+ '+': identity,
+ '-': negate,
+ '×': direction,
+ '÷': reciprocal,
+}
+
+func identity(d complex128) complex128 { return d }
+func negate(d complex128) complex128 { return -d }
+func direction(d complex128) complex128 { return d / complex(cmplx.Abs(d), 0) }
+func reciprocal(d complex128) complex128 { return 1.0 / d }