Stupid Haskell Trick: Factorials in the Type System

Jul 21, 2010 23:59



Ahh, summer! A time for backyard barbeques, ice cold beer, baseball games, and playing with experimental Haskell type system extensions. Or in my case, just the latter. In this article I'll show you how to compute factorials using Haskell's type system, i.e. at compile time.

Why would we want to do this? you may well ask. The real reason is ( Read more... )

Leave a comment

Comments 5

wizzard0 July 23 2010, 02:14:04 UTC
The most disturbing thing there is that i do understand how it works >_

Reply


once upon a time anonymous August 23 2010, 22:13:03 UTC
Just for a laugh, here's an antique type-level factorial function I cooked up a while back.

http://www.mail-archive.com/haskell-cafe@haskell.org/msg00692.html

I used the factorial to give a precise type to permutations, which I hope isn't entirely useless.

All the best

Conor

Reply

Re: once upon a time mvanier August 24 2010, 04:33:22 UTC
Conor,

I guess nothing in Haskell is ever completely useless ;-) Thanks for the link, I'll check it out!

Reply


More anonymous August 23 2010, 22:24:27 UTC
Now you need to extend it so you can use the type level factorial back at the value level again.

Reply

Re: More mvanier August 24 2010, 04:33:59 UTC
Yeah, I'll have to think about that.

Reply


Leave a comment

Up