aboutsummaryrefslogtreecommitdiff
path: root/monad.go
diff options
context:
space:
mode:
Diffstat (limited to 'monad.go')
-rw-r--r--monad.go15
1 files changed, 15 insertions, 0 deletions
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 }