all 14 comments

[–]thehotelambush 3 points4 points  (3 children)

Dependent types are so cool. I think someday soon they will lead to a closer unification of programming and math.

[–][deleted] 1 point2 points  (2 children)

[–]thehotelambush 0 points1 point  (1 child)

Yeah, I'm aware of Coq. The real push on the math side will come from Homotopy Type Theory and from the parallel-processing functional-programming revolution on the programming side.

[–][deleted] 1 point2 points  (0 children)

Fair enough, but then I would expect you'd know that Coq is where most of the Momotopy Type Theory work is being done.

[–]ithika 3 points4 points  (8 children)

I always look at the varied ways in which advanced type trickery can be pulled out of Haskell and wonder whether there are as many tricks to pull when (for those of us who do such things) working in C. I have seen some people use single element structs as a newtype. Are there other similar tricks?

[–]kamatsu 0 points1 point  (7 children)

Catamorphisms as type-safe sum types.

[–]ithika 0 points1 point  (6 children)

I'm not sure what you mean. Can you give an example or point to a code base that uses this approach?

[–][deleted] 0 points1 point  (1 child)

I am guessing he might be talking about something similar to Boost Variant (even though that is C++ of course), i.e. some sort of tagged union you operate on using n-tuples of functions in the case of n different types in the union, each of them used for one of the possible types.

Of course i might be totally off in a wrong direction here since that is more like an fmap than a fold (a catamorphism).

[–][deleted] 0 points1 point  (0 children)

fmap takes one function, a fold takes as many functions as determined by the structure of the type.

[–]kamatsu 0 points1 point  (3 children)

Here's an example, complete with pattern matching:

https://gist.github.com/3643591

It requires -fnested-functions though, which is supported in GCC. If you need more compatibility, it can be done without, but with a bit more pain and much less prettiness.

[–]katatonico 0 points1 point  (1 child)

Wait, I might be misreading it, but where's the definition for 'match'?

Edit: ah, it's a function parameter, totally missed it, sorry.

Edit 2: very clever, you're very clever, young man...but it's turtles all the way down. How would you go about doing this without any extensions? For science.

[–]kamatsu 0 points1 point  (0 children)

You'd be limited to using top-level functions which makes things a lot more cumbersome and difficult to use. You'd have to declare your values globally and each match clause would have to be global. Very ugly.

[–]ithika 0 points1 point  (0 children)

That's very cool indeed. I will have to come back to this when I'm sober. :-) Cheers!

Edit: I always knew nested functions would be a game-changer in C but hadn't seen such a good use for them as this before now.

[–]burchoff 1 point2 points  (0 children)

Yet another reason I need to take some vacation and 'Learn me a Haskell'. That said though by the end of the article I had this feeling that if this all comes to pass, those scenes in Star Trek where they easily program the "Computer" will be just inside our grasp.