From cb726fac520ed6336610d90af63c61044c51dfee Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sun, 29 Mar 2015 19:31:45 +0200 Subject: Experimental --- format.go | 15 ++++++++------- monad.go | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 monad.go 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 } -- cgit v1.2.3