diff options
Diffstat (limited to 'app/Operators.hs')
| -rw-r--r-- | app/Operators.hs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/app/Operators.hs b/app/Operators.hs new file mode 100644 index 0000000..8bf7c1e --- /dev/null +++ b/app/Operators.hs @@ -0,0 +1,42 @@ +module Operators where + +data Op = + Op Int Fixity + deriving (Show, Eq) + +data ArgKind + = X + | Y + deriving (Show, Eq) + +data Fixity + = Infix ArgKind ArgKind + | Prefix ArgKind + | Suffix ArgKind + deriving (Show, Eq) + +isPrefix (Prefix _) = True +isPrefix _ = False + +numArgs :: Op -> Int +numArgs (Op _ f) = go f + where + go (Infix _ _) = 2 + go _ = 1 + +type Ops = [(String, Op)] + +xfx, xfy, yfx, fx, fy, xf, yf :: String -> Int -> (String, Op) +xfx o p = (o, Op p (Infix X X)) + +xfy o p = (o, Op p (Infix X Y)) + +yfx o p = (o, Op p (Infix Y X)) + +fx o p = (o, Op p (Prefix X)) + +fy o p = (o, Op p (Prefix Y)) + +xf o p = (o, Op p (Suffix X)) + +yf o p = (o, Op p (Suffix Y)) |
