[go-nuts] Typed DSL in Go (or sum types and GADTs in Go)

2021-08-24 Thread Aram Hăvărneanu
Dear Go community,

For your delight, bemusement, or horror, I present to you generalized
algebraic data types in Go: https://play.golang.org/p/83fLiHDTSdY

| This file implements a deep embedding of a typed-DSL in Go.
| The representation is type-safe (we cannot construct ill-typed
| terms) and accepts multiple interpretations. The type system
| of the target language is identity-mapped to the Go type
| system such that type checking of the DSL is hoisted up to
| type-checking the Go code that contains the target language
| expression.
|
| Normally this requires either GADTs or higher-rank types.
| I show that it is possible to encode it in Go, a language
| which doesn't have GADTs (nor regular ADTs for that matter),
| nor higher-rank types. I exploit the duality between universal
| and existential quantification and encode sum types using
| the existential dual of the Boehm-Berarducci isomorphism.
| Unlike the Boehm-Berarducci encoding, my encoding is not
| universally-quantified, but existentially quantified, and
| does not require higher-rank polymorphism capitalizing on
| the fact that Go interfaces are existential types.
|
| Just like an algebraic data type, my encoding is closed,
| its usage is type safe, and the match operations are checked
| at compile-time for exhaustivness.
|
| A related, alternative encoding would be to encode the GADT
| into tagless-final style. This requires polymorphic terms,
| which in Go can only be functions, which are not serializable.
| My encoding is bidirectionally serializable.
|
| As presented, the encoding is closed because I want to show
| that I can encode every GADT property. It is also possible,
| and perhaps desirable to make the encoding open, which
| solves the Expression Problem.
|
| Although GADT invariants are encoded using Go generics
| (which are a form of universal quantification) the encoding
| does not require that the Curry–Howard isomorphism holds,
| it is purely existential.  In fact, if one only wants plain
| ADTs, generics are not needed at all. Go can encode sum
| types, and was always able to.

You will need Go tip to compile this.

-- 
Aram Hăvărneanu

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAEAzY381kQ0hptu1GbPwKHWAjyUXCj31HoVnOVcCvuXZhSo4rw%40mail.gmail.com.


Re: [go-nuts] Makefiles for Go Programs

2021-08-24 Thread Wojciech S. Czarnecki
Dnia 2021-08-24, o godz. 07:54:35
Reto  napisał(a):

> It may be nicer, however the beauty of make is that it is ubiquitous,
> everybody already has it.

No, not everybody has it. Esp. on Windows host.

> With mage, your installation instructions now need to contain how /
> where to get mage in the first place, leaving the user with a random
> binary somewhere which they probably never ever need nor update again.

Nope. If user is going to compile from sources she also needs to install Go 
compiler and tools. Once she has it the mage is a `go install` command away. 
Shorter than typical line of "prerequisites" needed by non-developer user on 
most of linux distros. (If she is about to install binary she does not need 
mage at all - 99% deployments of Go based apps are just the single executable.)

> leaving the user with ... they probably never ever need nor update again.

Make does not come alone for end-users. Usually it comes bundled with several 
hundreds of megabytes of the devel packages
user gets after issuing eg. `sudo apt-get install build-essential`. Then she's 
left with a bit more more unused stuff than a single
mage binary.

TC,

-- 
Wojciech S. Czarnecki
 << ^oo^ >> OHIR-RIPE

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/20210824130426.40fd40c2%40xmint.