Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- So I want to make a strong static typed Lisp that is as espressive and as concise as a dynamic typed Lisp.
- I want do this by having the type checker be able to infer types as much as possible.
- ```
- (defn identity [x] x)
- -> namespace/identity[A](A): A
- (defn fun [f col] (map f col))
- -> namespace/fun[A, B](A -> B, Functor<A>): Functor[B]
- ```
- In this example, the compiler should be able to understand the types implicitly from the body of the function.
- Something like this wouldn't compile though
- ```
- ((fn [f col] (map f col)) identity 1)
- -> TypeClassNotFoundError. Could not find instance of Functor for Int
- other information like line number and what symbol caused the type error
- (() identity)
- -> NotAFunctionError. Unit is not a Function
- line number and symbol
- ```
- Also unlike Unit, Map and Vector are functions. (A) -> B and (Int) -> A respectively.
- ```
- (def m {:a 1 :b 2})
- (dev v [:a :b])
- (m :a)
- -> 1
- (m 12)
- -> Nil
- (v 1)
- -> :b
- (v 2)
- -> Nil
- ```
- Accessing an index that does not exist returns Nil not throw an exception.
- It's also possible to annotate all of the types
- ```
- (defn fun [f: (Int) -> Int col: Vector[Int]] [Vector[Int]] (map f col))
- ```
- To make this possible, the type checker should be able to understand typeclasses.
- ```
- (def-typeclass Functor[A[_]] (pure [B] [A[B]]) (map [(B) -> C A[B]] [A[C]]))
- (def-type Maybe (Just value) Nil)
- (def-functor Maybe
- (pure [value] (Just value))
- (map [f this]
- (when-not nil? (Just value))))
- ```
- So im trying to think how I actually want to define types. I like the idea of a super type followed by subtypes and their parameters.
- ```
- (def-type Maybe (Just value) Nil)
- (def-type Tree (Branch left: Tree right: Tree) Nil)
- (def-type List (Cons head tail: List) Nil)
- ```
- but how do I differentiate that between fields.
- ```
- (def-type TypeA some-generic some-int: Int)
- ```
- maybe I enclose fields in a vector
- ```
- (def-type Maybe (Just [value]) Nil)
- (def-type Tree (Branch [left: Tree right: Tree]) Nil)
- (def-type List (Cons [head tail: List]) Nil)
- (def-type TypeA [some-generic some-int: Int])
- ```
- Do I want to handle inheritence?
- How do I handle sub types that use that provide explicit type parameters to the super type?
- ```
- (def-type Xor [A B] (Left [A Nothing] [left: A]) (Right [Nothing B] [right: B]))
- ```
- How do I handle inheritence that overrides or provides a default value to a super type
- ```
- (def-type Animal [name: String] (Ferret [name = "Ferret"]))
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement