Did you know ... | Search Documentation: |
Packs (add-ons) for SWI-Prolog |
Title: | The maybe type represents an optional value |
---|---|
Rating: | Not rated. Create the first rating! |
Latest version: | 0.1.1 |
SHA1 sum: | 11bfc624970bd914d2a4f2bf2f851e4653e28db9 |
Author: | Michael Hendricks <michael@ndrix.org> |
Maintainer: | Michael Hendricks <michael@ndrix.org> |
Packager: | Michael Hendricks <michael@ndrix.org> |
Home page: | http://packs.ndrix.com/maybe/index.html |
Download URL: | http://packs.ndrix.com/maybe/maybe-0.1.1.tgz |
No reviews. Create the first review!.
Version | SHA1 | #Downloads | URL |
---|---|---|---|
0.0.1 | f13fb3dd15c0f23f872c277f726e083d43e0358f | 1 | http://packs.ndrix.com/maybe/maybe-0.0.1.tgz |
0.0.2 | 285a9f0916777dc503497adaebde54fb04a1121c | 1 | http://packs.ndrix.com/maybe/maybe-0.0.2.tgz |
0.1.0 | 021777db88dad61ac7f13f1fd51562e048c59296 | 1 | http://packs.ndrix.com/maybe/maybe-0.1.0.tgz |
0.1.1 | 11bfc624970bd914d2a4f2bf2f851e4653e28db9 | 71 | http://packs.ndrix.com/maybe/maybe-0.1.1.tgz |
:- use_module(library(maybe)). % staff(Name, Spouse) staff(tom, just(teresa)). staff(bob, nothing). staff(sue, just(william)). ?- staff(Name, MaybeSpouse), maybe_default_value(MaybeSpouse, '(none)', Spouse). Name = tom, Spouse = teresa ; Name = bob, Spouse = '(none)' ; Name = sue, Spouse = william.
The maybe
type encapsulates an optional value. When a value is present, we have just(Value)
. When it's absent we have nothing
. In some circumstances, this can be a more natural model than using Prolog failure. For example, one might model a nullable SQL column using maybe
.
This module draws inspiration from similar libraries for Mercury and Haskell. We make predicates available even where it's clearer to use unification. That facilitates using maybe values with maplist
and friends.
In addition to the predicates described below, this module defines clauses for the multifile predicate error:has_type/2 which describe the type maybe
and maybe(T)
where T is a type parameter. It also defines clauses for working with library(quickcheck)
.
Using SWI-Prolog 6.3 or later:
?- pack_install(maybe).
This module uses semantic versioning.
Source code available and pull requests accepted at http://github.com/mndrix/maybe
Pack contains 7 files holding a total of 10.0K bytes.