aboutsummaryrefslogtreecommitdiff
path: root/monad.go
blob: 14a1d68fe5246bbbbb1cb74c535c1ec4cbe27645 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 }