3 ms·
I can't wait until Lamdu supports something equivalent to standard Haskell 98. Right now, it is hard to do anything useful. For example, I tried to du Project E
by iso-8859-1 11y ago
I can't wait until Lamdu supports something equivalent to standard Haskell 98. Right now, it is hard to do anything useful. For example, I tried to du Project Euler's 3rd problem, but I couldn't, since I needed cons and it is a sum type constructor and they are not implemented yet.
- Peaker 11y agoThere 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.
- yairchu 11y agoHere's how Euler 3 looks: http://imgur.com/Y9qryWd http://imgur.com/Y9qryWd Note that not seen in the screenshot are the `reduce` and `max` functions which I've implemented, though those are pretty simple. I also can't wait till I'll be able to really use Lamdu.