Skip to content

Instantly share code, notes, and snippets.

View made2591's full-sized avatar
🎯
Focusing

Matteo Madeddu made2591

🎯
Focusing
View GitHub Profile
...
x := 0
fmt.Printf("%s\n", bind(bind(bind(unit(x), f1), f2), f3).ToString())
...
...
// no more required and not repeated
log += log2 + "; "
log += log3 + "; "
...
...
func bind(x *Log, f Increment) *Log {
val, op := f(x.Val)
return &Log{Val: val, Op: fmt.Sprintf("%s%s; ", x.Op, op)}
}
...
...
func unit(x int) *Log {
return &Log{Val: x, Op: ""}
}
...
...
type Increment func(y int) (int, string)
type Log struct {
Val int
Op string
}
...
...
func unit(x int) *Log {
return &Log{Val: x, Op: ""}
}
func bind(x *Log, f Increment) *Log {
...
x := 0
log := "Ops: "
res, log1 := f1(x)
log += log1 + "; "
res, log2 := f2(res)
log += log2 + "; "
...
func f1(x int) (int, string) {
return x + 1, fmt.Sprintf("%d+1", x)
}
func f2(x int) (int, string) {
@made2591
made2591 / mm.go
Created January 14, 2020 22:03
Monad in go
package main
import (
"fmt"
)
func f1(x int) (int, string) {
return x + 1, fmt.Sprintf("%d+1", x)
@made2591
made2591 / keybase.md
Created August 13, 2019 08:09
My keybase proof

Keybase proof

I hereby claim:

  • I am made2591 on github.
  • I am made2591 (https://keybase.io/made2591) on keybase.
  • I have a public key whose fingerprint is 465F 151A 2CB3 B5E3 3A13 83ED D623 0745 6844 BE6C

To claim this, I am signing this object: