Live data from Hacker News

Sugar – a typed lispy language targeting webasm/wat

ph1lter.bitbucket.io

1–10 of 28 posts

Re: Sugar – a typed lispy language targeting webasm/wat

#3
TIL that there's a format called wat, which means "WebAssembly text format" and it can be converted to wasm (and back to wat).

This format uses S-expressions like lisp, and it's got a stack machine like forth. [1] [2]

I'm a bit surprised something so mainstream ended up being a lispy forth.

[1] https://ph1lter.bitbucket.io/blog/2020-12-03-webasm-forth-wi... [2] https://developer.mozilla.org/en-US/docs/WebAssembly/Underst...

Re: Sugar – a typed lispy language targeting webasm/wat

#4
post #3

TIL that there's a format called wat, which means "WebAssembly text format" and it can be converted to wasm (and back to wat). This format uses S-expressions like lisp, and it's got a stack machine like forth. [1] [2] I'm a bit surprised something so mainstream ended up being a lispy forth. [1] https://ph1lter.bitbucket.io/blog/2020-12-03-webasm-forth-wi... [2] https://developer.mozilla.org/en-US/docs/WebAssembly/Und…

TIL that TIL means "Today I Learned".

Thanks for reading the post :)

Update 2020-12-07: There was a bug in the macro expansion logic. I've backported the fix to the linked source and explained the bug in the 'mistakes' section.

Re: Sugar – a typed lispy language targeting webasm/wat

#6
I know WebAssembly language (WASM), as the thing Dfinity (https://sdk.dfinity.org/docs/index.html) uses. They have a nice language called Motoko (https://sdk.dfinity.org/docs/language-guide/motoko.html) I was playing with. But I like the idea of this kind of Lispy Forth.

Re: Sugar – a typed lispy language targeting webasm/wat

#9

When I read about a new typed Lisp I always hope to see a Lisp with Haskell-like type annotations. Is this easily feasible? That would be real sugar .

What do you mean by Haskell-like type annotations?

Do you mean literally the syntax

    foo :: Type0 -> Type1 -> Type2
? Or do you mean the ability to have the type annotation on a separate line from the function implementation itself (rather than e.g. annotating its arguments individually)?

In the case of the former you have Hackett (https://lexi-lambda.github.io/hackett/reference-syntactic-fo...) which unfortunately I think isn't seeing too much work on it anymore.

In the latter case something like Typed Clojure may work (https://github.com/clojure/core.typed).

Re: Sugar – a typed lispy language targeting webasm/wat

#10

When I read about a new typed Lisp I always hope to see a Lisp with Haskell-like type annotations. Is this easily feasible? That would be real sugar .

Typed Racket is pretty close. I imagine that with some work and Racket's macro and module system that someone could rewrite it to be more ML-like in syntax.

In the Coursera course Programming Languages, I ported some of the first assignments from SML to F# and Typed Racket, and you can see the similarities of type annotations in the very simple examples below.

SML:

    (* Helper function. Takes a generic list and an integer n and returns the nth element of the list. *)
    fun get_nth_element (xs : 'a list, n : int) =
        if n = 1
        then hd xs
        else get_nth_element(tl xs, n-1)

    (* Takes a list of strings and an integer n and returns the nth element of the list. *)
    fun get_nth (strings : string list, n : int) =  get_nth_element(strings,n)
F#:

    /// Helper function. Takes a generic list and an integer n and returns the nth element of the list.
    let rec getNthElement (xs : 'a list, n : int) =
        if n = 1
        then List.head xs
        else getNthElement(List.tail xs, n-1)

    /// Takes a list of strings and an integer n and returns the nth element of the list.
    let getNth (strings : string list, n : int) =  getNthElement(strings,n)
Racket:

    #lang typed/racket

    ;; Helper function. Takes a generic list and an integer n and returns the nth element of the list.
    (: get-nth-element (All (T) (Listof T) Integer -> T))
    (define (get-nth-element xs n)
      (if (equal? n 1)
          (first xs)
          (get-nth-element (rest xs) (- n 1))))

    ;; Takes a list of strings and an integer n and returns the nth element of the list.
    (: get-nth ((Listof String) Integer -> String))
    (define (get-nth strings n) (get-nth-element strings n))
Post reply on HN