14.11.2012 Views

Curry: An Integrated Functional Logic Language

Curry: An Integrated Functional Logic Language

Curry: An Integrated Functional Logic Language

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

-- (flip f) is identical to f but with the order of arguments reversed<br />

flip :: (a -> b -> c) -> b -> a -> c<br />

flip f x y = f y x<br />

-- Repeat application of a function until a predicate holds<br />

until :: (a -> Bool) -> (a -> a) -> a -> a<br />

until p f x = if p x then x else until p f (f x)<br />

-- Right-associative application<br />

($) :: (a -> b) -> a -> b<br />

f $ x = f x<br />

-- Evaluate the first argument to head normal form and return the<br />

-- second argument. Suspend if the first argument evaluates to a<br />

-- free variable.<br />

seq :: a -> b -> b<br />

-- Right-associative application with strict evaluation of its argument.<br />

($!) :: (a -> b) -> a -> b<br />

f $! x = x ‘seq‘ f x<br />

-- Abort the execution with an error message<br />

error :: String -> _<br />

-- failed is a non-reducible polymorphic function.<br />

-- It is useful to express a failure in a search branch of the execution.<br />

failed :: _<br />

failed | 1=:=2 = x where x free<br />

-- Boolean values<br />

data Bool = True | False<br />

-- Sequential conjunction<br />

(&&) :: Bool -> Bool -> Bool<br />

True && x = x<br />

False && _ = False<br />

-- Sequential disjunction<br />

(||) :: Bool -> Bool -> Bool<br />

True || _ = True<br />

False || x = x<br />

-- Negation<br />

47

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!