[racket] [plt-scheme] Re: Typed scheme: Cannot apply expression of type Procedure, since it is not a function type

From: Anthony Cowley (acowley at seas.upenn.edu)
Date: Sat Jun 5 11:04:21 EDT 2010

On Sat, Jun 5, 2010 at 2:44 AM, keydana at gmx.de <keydana at gmx.de> wrote:
> so products and sums would be isomorphic?

No, dual means that the arrows are reversed. For a product, you have
two projections: arrows from the product to its constituent parts. For
a (binary) sum, you have two arrows injecting values into the sum.
That is, a sum can be created either by providing a value on the left,
or on the right.

In practice, I think it is more helpful to think about functions that
take these types as arguments. A function that takes a product of type
A x B (written (a,b) in Haskell) will look like so,

foo (x,y) = if x < 2 then y * 3 else y - 4

Note that both an A *and* a B are available to the function. Or, from
the other direction, a caller must provide *both*.

With sums, the key word is "either." A function on a sum type A | B
must be defined if it is given an A, *or* if it is given a B. This is
usually handled with pattern matching on type constructors,
bar (Left x) = x + 2
bar (Right y) = 5

In these silly examples,  A and B can be different numeric types, foo
returns a B while bar returns an A.

Anthony
_________________________________________________
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


Posted on the users mailing list.