4 ms·
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.
by galfarragem 6y ago
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.
- dwohnitmok 6y agoWhat 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-forms.html#%28part._reference-type-annotation%29 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 https://github.com/clojure/core.typed).
- bmitc 6y agoTyped 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))
- krageon 6y agolisp can already be typed
- moonchild 6y agoYou may be interested in coalton, an ml dialect embedded in cl - https://github.com/stylewarning/coalton https://github.com/stylewarning/coalton