Code Monkey home page Code Monkey logo

maybe's Introduction

Synopsis

:- 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.

Description

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).

Changes in this Version

  • Add meta_predicate declarations for
    • call_maybe/3
    • map_maybe/3
    • fold_maybe/4

Installation

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

maybe's People

Contributors

mndrix avatar

Stargazers

Tadeusz Kurpiel avatar Angus H. avatar Sebastian Godelet avatar

Watchers

James Cloos avatar  avatar

maybe's Issues

redefine type using library(typedef)

The definition is simple:

:- type maybe(T) ---> nothing ; just(T).
:- type maybe == maybe(any).

This makes the type definition clearer and leverages all future work on library(typedef).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.