Live data from Hacker News

FP-Go: Functional programming library for Golang

github.com

21–30 of 185 posts

Re: FP-Go: Functional programming library for Golang

#21
post #14

Earlier quoted context omitted.

Either is nearly in the language anyways. The vast majority of pragmatic go functions will return [Result, Error] and or just [Error]. We are only missing support to treat this as a monad.

Either as a pattern is _used_ everywhere, but the standard library in go doesn't have one (people just use a tuple), so it's _always_ encoded wrong. It's very annoying.

There is no tuple type in go. When you see a func() (A, error) that is not a function returning a tuple. It is a function returning two values that cannot be composed. You can't A(B()) if B returns two values. It's pure comedy.

Re: FP-Go: Functional programming library for Golang

#22
post #14

Earlier quoted context omitted.

Either as a pattern is _used_ everywhere, but the standard library in go doesn't have one (people just use a tuple), so it's _always_ encoded wrong. It's very annoying.

There is no tuple type in go. When you see a func() (A, error) that is not a function returning a tuple. It is a function returning two values that cannot be composed. You can't A(B()) if B returns two values. It's pure comedy.

[deleted]

Re: FP-Go: Functional programming library for Golang

#23
post #14

Earlier quoted context omitted.

Either as a pattern is _used_ everywhere, but the standard library in go doesn't have one (people just use a tuple), so it's _always_ encoded wrong. It's very annoying.

There is no tuple type in go. When you see a func() (A, error) that is not a function returning a tuple. It is a function returning two values that cannot be composed. You can't A(B()) if B returns two values. It's pure comedy.

> You can't A(B()) if B returns two values.

You can if A is a function which takes two arguments, e.g.

  package main

  import "log"

  func A(x, y int) { log.Printf("%d, %d", x, y) }
  func B() (int, int) { return 1, 2 }
  func main() { A(B()) }
https://go.dev/play/p/Jp4B0L6NJj2

Re: FP-Go: Functional programming library for Golang

#25

Earlier quoted context omitted.

There is no tuple type in go. When you see a func() (A, error) that is not a function returning a tuple. It is a function returning two values that cannot be composed. You can't A(B()) if B returns two values. It's pure comedy.

> You can't A(B()) if B returns two values. You can if A is a function which takes two arguments, e.g. package main import "log" func A(x, y int) { log.Printf("%d, %d", x, y) } func B() (int, int) { return 1, 2 } func main() { A(B()) } https://go.dev/play/p/Jp4B0L6NJj2

What you can't do is a(b(), c()) unless b and c return single values.

And there are no slices or channels of tuples, return values must be destructured right away.

Re: FP-Go: Functional programming library for Golang

#26
AIUI, Go intentionally avoids programming language features considered too advanced by its authors in order to lower the bar (to make it easier for most programmers to pick up, that is) and to keep the code uniform, supposedly to the advantage of companies using it. While hammering unidiomatic approaches into a language virtually always is awkward: there are other libraries and programmers, even if you are fine with the rules you have to follow in order to emulate the desirable features using a library. The combination of those things looks even stranger than they do separately.
Post reply on HN