Re: typing callcc
Matthias Blume <[email protected]>
| Newsgroups | gmane.comp.lang.sml.smlnj |
|---|---|
| Message-ID | <[email protected]> |
On Jan 29, 2005, at 10:07 PM, David Van Horn wrote: > Perhaps this is obvious or a FAQ, but why does the following example > (from > Harper, Duba, and MacQueen) result in a type error? > > callcc(fn k => if true then [ (throw k 3) + 1 ] else 5 :: (throw k 4)) The return value of the function given as an argument to callcc is int list. Thus, the value of the call to callcc is also int list. Thus, the continuation captured by callcc takes an int list. But you try to pass an int. > stdIn:2.1-2.71 Error: operator and operand don't agree [literal] > operator domain: int cont -> int > operand: int cont -> int list > in expression: > callcc (fn k => if true then <exp> :: <exp> else <exp> :: <exp>) As you see, the compiler follows this chain in the opposite direction: You throw an int, so the continuation captured by callcc must take an int, so the call of callcc must produce an int, but the function that is the argument to callcc (which normally provides the result of the call to callcc) returns an int list. Matthias ------------------------------------------------------- This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting Tool for open source databases. Create drag-&-drop reports. Save time by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc. Download a FREE copy at http://www.intelliview.com/go/osdn_nl