3 ms·
There is a built in cons (in the type Stream which is a lazy list). Sum constructors are supported but creating custom ones currently has a very cumbersome ui.
by Peaker 11y ago
There is a built in cons (in the type Stream which is a lazy list).
Sum constructors are supported but creating custom ones currently has a very cumbersome ui.
- iso-8859-1 11y agoHow do I use that built-in cons? What do I call it and how does it look? Is it visible in Yairchu's Euler problem 3 example?
- yairchu 11y agoIn the example it is called "NonEmpty". There's the "Stream" nominal type, shown below in Haskell-like text syntax: newtype Stream a = () -> (Empty | NonEmpty { head :: a, tail :: Stream a }) To construct a "Stream", we type "stream" in a hole and pick "Stream« ◗ _", which wraps a "deferred computation" ("◗ _") in the nominal "Stream" type constructor. Now the type of the value inside the hole within is just "Empty | NonEmpty { head :: a, tail :: Stream a }", now type "nonempty" and pick it.
- Peaker 11y agoYeah, in Yairchu's euler solution, it is called "NonEmpty". Lamdu has a nominal type called "Stream" (nominal types are basically like Haskell's newtypes). You can refer to them via their names in holes. The purple arrows represent packing/unpacking depending on which side they appear. The Stream nominal type has a single type parameter `a` which is the item type, and is defined as: Stream a = () -> (Empty + NonEmpty { head :: a, tail :: Stream a }) (Note the + above is type-level plus, a sum type). So inside the Stream you find a function from unit (representing lazy computation) to a sum type of 2 cases: Empty - equivalent to Haskell's [] NonEmpty - a cons, equivalent to (:) The NonEmpty case has 2 named parameters (head, tail). Maybe it will become an infix (:) in the future. When you pack a Stream nominal, Lamdu auto-completes the lazy suspension (half circle character), and then lets you fill in `Empty` or `NonEmpty`. When you unpack a Stream nominal, Lamdu offers completions that force the suspended computation (apply with `()`) and then do case analysis (represented by a colon) on each of the sum constructors.