packages feed

egison-4.1.0: lib/core/base.egi

--
--
-- Base
--
--

def eq :=
  matcher
    | #$val as () with
      | $tgt -> if val = tgt then [()] else []
    | $ as (something) with
      | $tgt -> [tgt]

def bool := eq
def char := eq
def integer := eq
def float := eq

--
-- Utility
--

def id := 1#%1

def fst (x, y) := x
def snd (x, y) := y

infixr expression 0 $

def ($) f x := f x

def compose f g := \x -> g (f x)

def flip fn := \$x $y -> fn y x

def eqAs a x y :=
  match x as a with
    | #y -> True
    | _ -> False

def curry f x y := f (x, y)
def uncurry f (x, y) := f x y

--
-- Boolean
--

infixr expression 3 &&
infixr expression 2 ||

def (&&) b1 b2 := if b1 then b2 else False
def (||) b1 b2 := if b1 then True else b2

def not b := if b then False else True

--
-- Unordered Pair
--

def unorderedPair m :=
  matcher
    | ($, $) as (m, m) with
      | ($x, $y) -> [(x, y), (y, x)]
    | $ as (eq) with
      | $tgt -> [tgt]