Ann: maybe pack
Michael Hendricks <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <CAFHuXuYoa_XF33coQdpWTagbYfFVL60Ef-hP7eAxkySa4-abRw@mail.gmail.com> |
I uploaded the maybe pack <http://www.swi-prolog.org/pack/list?p=maybe>which defines a type and predicates for working with optional values. The type is modeled on maybe types from Mercury and Haskell. Semidet predicates sometimes eliminate the need for maybe values in Prolog. In other circumstances, a maybe can be more natural. Some Prolog code uses unbound variables to indicate missing values. library(uri) is one example. I find that style difficult to work with because one must avoid binding the variable by accident during unification. A maybe type also helps distinguish between "I don't know the value yet" (unbound variable) and "I know the value to be absent" (nothing). For those unfamiliar with the convention, a maybe value is either 'nothing' or 'just(Value)'. 'nothing' indicates that there is no value. 'just(Value)' indicates that the value is Value. Enjoy. -- Michael -------------- next part -------------- HTML attachment scrubbed and removed