Catalog of computation strategies

Submitted by metaperl on Mon, 04/24/2006 - 2:38pm.
when something may or may not return a value
use Maybe

when something may return 0,1 or more values
use a List... but ask yourself: isn't Maybe just a subcase of list? We can restate Maybe as something which returns 0 or 1 value while we can see a list of something which may return 0..n values.
Pardon me while the brainstorm continues, but I just thought about the children of an n-ary tree - asking for children of a node returns a list which is a monad.
Submitted by lightstep on Wed, 04/26/2006 - 10:26am.

A general type constructor for trees would need to get the amounts for the children of each node:
Tree :: * -> [Integer] -> *
type TwoThreeTree a = Tree a [0,2,3]

However, in haskell we don't have dependent types, so we need to pass a general type-function to Tree, with kind (* -> *), that would construct the type for all the children of a node from the type of one node:
Tree :: * -> (* -> *) -> *
data Tree a mult = Tree (a, mult (Tree a mult))
data TwoThreeMult a = Nil | Two (a, a) | Three (a, a, a)
type TwoThreeTree a = Tree a TwoThreeMult

Submitted by lightstep on Wed, 04/26/2006 - 10:28am.

I forgot to add that the `mult' parameter of `Tree' will always be a functor. This will enable generic traversal operations for trees.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.