User:Zzo38/Proposal for macros
Jump to navigation
Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
This document list proposal for use of macros in Haskell.
Defining macros
Macros for catching pattern failure
Example:
a :: Int -> Int -> Int; a 0 x = x; a 1 x = x + x; b :: Int -> Int -> Either String Int; b = _Catch 2 a; c :: Int -> Int -> IO Int; c = _CatchIO 2 a; d :: Int -> IO (Int -> Int); d = _CatchIO 1 a; e :: [String]; e = ["hello", "world", undefined]; f :: IO [String]; f = _CatchStrictIO 0 e do { case _This of { [] <- _Stop; h : t <- do { h; _Again t; }; }; };
Meanings:
b 0 = Right; b 2 = const $ Left "pattern match error"; c 0 = return; c 2 = const $ fail "pattern match error"; d 0 = return id; f = fail "undefined";