Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456 Definitions
Definitions
There are several improvements to the basic form of definitions in
records.
Signature definitions
Haskell style definitions with a type signature and a definition can
be used.
defn ::= labelid :: type ; labelid = expr
Example:
x :: Int;
x = 5;
Function definitions
Haskell style function definitions can also be used, i.e., when the
right hand side of a definitions is a lambda expression the bound
variables can be moved to the left. If there is a signature as well
the types on the variables can be left out.
defn ::= labelid :: type ; labelidvarid ... = expr
Example:
inc :: Int->Int;
inx x = x+1;
Function definitions by pattern matching
Functions can be defined with pattern matching, as in Haskell.
Nested patterns as well wildcards, '_', can be used.
Example:
not :: Bool -> Bool;
not (False) = True;
not (True) = False;
Patterns in Cayenne are similar to those in Haskell.
For definitions of type # there is a special shorthand.
The :: # part can be left out if the keyword
type is prepended to the definition. Furthermore, if the
an argument to a type definition has type #
the type can be left off.
defn ::= type labelidvardecl ... = type vardecl ::= varid | ( varid :: type )
Example:
type MyInt = Int;
type PairX a = Pair a a;
Data type definitions
When definitions a data type you normally want ordinary names for the
constructors. A Haskell-like data type definition construct can be
used to define a type and the constructors at the same time.
List :: # -> # = \ (a :: #) -> data Nil | Cons a (List a);
Nil :: (a :: #) |-> List a = Nil@(List a);
Cons :: (a :: #) |-> a -> List a -> List a = Cons@(List a);
Open definition
The open definition provides a convenient way to get
access to many components of a record and use them locally within
another record.
defn ::= open expr use [modifier] varid :: type [ =
varid ], ... ;
The definition open e use i1::t1=i1', i2::t2=i2', ... ;
is (semantically) equivalent to the definitions private i1::t1 = e.i1'; private i2::t2 = e.i2'; ...
If the second varid is left out it is assumed to be the same as
the first. The types can be omitted. So you normally write just open e use i1, i2, ... ;
The default visibility is private, but this can be overridden either
in front of the open definition, or individually.
Omitting type signatures
If a definition is not a function definition, and it is not recursive
(or part of a mutual recursive group) the type signature can almost
always be dropped.
Example:
struct { x = 5; y = 7; }
Type signatures can also me omitted if the record that the definition
occurs in has a type signature.