Hacker News new | past | comments | ask | show | jobs | submit login

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.



Here's how Euler 3 looks: 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.


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.


How 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?


Yeah, 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.


In 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.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: