Grade Counter
You could presumably use FooType to optionally interrupt a recursive function earlier: for example, take this code:
foo _ 0 = 1 foo (Foo x) n = n * foo x (n-1)
If you call foo allTheFoos , you get an equal factorial function. But you can pass another value of type FooType , for example.
atMostFiveSteps = Foo (Foo (Foo (Foo (Foo (error "out of steps")))))
and then foo atMostFiveSteps will only work for values less than 6.
I also do not say that this is especially useful, and that this is the best way to implement such a function ...
Type of emptiness
BTW, there is a similar design, namely
newtype FooType' = Foo' FooType'
which is useful: this is one way to determine the type of void that has no values other than ⊥. You can still determine
allTheFoos' = Foo' allTheFoos'
as before, but since Foo does nothing expeditiously, this is equivalent to x = x and therefore also ⊥.
source share