package main import "math/cmplx" var monads = map[rune]Monad{ '+': conjugate, '-': negate, '×': direction, '÷': reciprocal, } func conjugate(w complex128) complex128 { return cmplx.Conj(w) } func negate(w complex128) complex128 { return -w } func direction(w complex128) complex128 { return w / complex(cmplx.Abs(w), 0) } func reciprocal(w complex128) complex128 { return 1.0 / w } var dyads = map[rune]Dyad{ '+': plus, '-': minus, '×': times, '÷': divide, } func plus(a, w complex128) complex128 { return a + w } func minus(a, w complex128) complex128 { return a - w } func times(a, w complex128) complex128 { return a * w } func divide(a, w complex128) complex128 { return a / w }