VSL - The prelude.option Structure

# Copyright 2011  Petter Urkedal
#
# This file is part of the Viz Standard Library <http://www.vizlang.org/>.
#
# The Viz Standard Library (VSL) is free software: you can redistribute it
# and/or modify it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# The VSL is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
# more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with the VSL.  If not, see <http://www.gnu.org/licenses/>.

open prereq
open effect

let is_empty
    at none% be true
    at some _ be false

let get
    at none% fail "option.get none%"
    at some x be x

let default x
    at none% be x
    at some y be y

let map f
    at none% be none
    at some x be some (f x)

let fold f
    at none% be x  x
    at some x be f x

let for_all f
    at none% be true
    at some x be f x

let for_some f
    at none% be false
    at some x be f x

let iter f
    at none% be return ()
    at some x be f x

let filter f
    at none% be none
    at some x if f x be some x
	      else   be none

let flatten
    at some (some x) be some x
    at _ be none