Personal tools

User:Zzo38/Proposal for macros

From HaskellWiki

< User:Zzo38
Revision as of 19:53, 12 January 2012 by Zzo38 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This document list proposal for use of macros in Haskell.

1 Defining macros

2 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";