Chapter 4 The Edison PreludeThe EdisonPrelude module defines a few widely-used
utility types and classes. It is imported by every other module
in Edison, and by most clients. (It would be imported by all clients,
except that many modules re-export the relevant prelude entries.)
Currently, the EdisonPrelude defines two types in the
Maybe family, and three classes related to hashing.
data Maybe2 a b = Just2 a b | Nothing2
data Maybe3 a b c = Just3 a b c | Nothing3
class Eq a => Hash a where
hash :: a -> Int
-- forall x,y :: a. (x == y) implies (hash x == hash y)
class Hash a => UniqueHash a
-- no new methods, just a stronger invariant
-- forall x,y :: a. (x == y) iff (hash x == hash y)
class UniqueHash a => ReversibleHash a where
unhash :: Int -> a
-- forall x :: a. unhash (hash x) == x
The Maybe2 and Maybe3 types are used as the return types of
functions that destructure a container, returning the element (or a key and
element) together with the remaining container.
The Hash classes are used to build functional analogs to
traditional imperative hash tables.
This module will gradually be expanded to include utility functions
on the Maybe2 and Maybe3 types, and perhaps a few other
widely-used types or functions (such as warn).