Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition of a Void module #31

Open
HarrisonGrodin opened this issue Feb 10, 2021 · 4 comments
Open

Addition of a Void module #31

HarrisonGrodin opened this issue Feb 10, 2021 · 4 comments

Comments

@HarrisonGrodin
Copy link

Unsure if this is the best format/place for a new proposal (or if I should, say, create a Wiki page). If there's something else I should do, please let me know!


Often, it is useful to have access to an empty "void" type. A simple proposal might look like this:

signature VOID =
  sig
    type void
    type t = void
    val absurd : t -> 'a
  end

structure Void :> VOID =
  struct
    datatype void = Void of void
    type t = void
    fun absurd (Void v) = absurd v
  end

Perhaps a few other auxiliary functions could be useful, as well. For example:

    val fail : string -> t  (* raises `Fail` *)
    val asLeft : ('a,t) either -> 'a
    val asRight : (t,'a) either -> 'a
@dmacqueen
Copy link

dmacqueen commented Feb 14, 2021 via email

@ratmice
Copy link

ratmice commented Feb 14, 2021

Also discussed in here: SMLFamily/Successor-ML#32

@RobertHarper
Copy link
Contributor

RobertHarper commented Feb 14, 2021 via email

@HarrisonGrodin
Copy link
Author

While there isn't any particular reason to produce a value of type void as opposed to a new type variable, there are plenty of parameterized datatypes which would benefit from having one parameter set to void. A good example was given in the issue @ratmice mentioned; to add on, void is quite useful in conjunction with recursive types:

datatype 'a term = Var of 'a | Node of string * 'a term list

(* simple example *)
fun traverse (t : void term) : string list =
  case t of
    Var v => absurd v
  | Node (s, children) => s :: List.concatMap traverse children

Here, it's useful to discuss both string terms (terms containing variables) and void terms (ground terms - impossible to have a Var), often at the same time. For example:

val match : string term * void term -> void term StringDict.t

Similarly, with intrinsically-scoped lambda terms, void serves as the empty context:

datatype 'a lam = Var of 'a | App of 'a lam * 'a lam | Lam of 'a option lam

type closed = void lam
val I : closed = Lam (Var NONE)
val K : closed = Lam (Lam (Var (SOME NONE)))
val invalid : closed = Var (raise Fail "impossible")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants