Skip to content

Instantly share code, notes, and snippets.

@fronx
Last active August 29, 2015 14:04
Show Gist options
  • Save fronx/832f081a6c7620872130 to your computer and use it in GitHub Desktop.
Save fronx/832f081a6c7620872130 to your computer and use it in GitHub Desktop.
instance (Num a, Show a) => Show (FnShow a) where
show (FnShow1 fnStr fn) =
concat (map showFn [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
where showFn n = fnStr ++ " " ++ show n ++ " = " ++ show (fn n) ++ "\n"
show (FnShow2 fnStr fn) =
concat (map showOp [0, 1, 2, 3])
where showOp n = show (FnShow1 (fnStr ++ " " ++ show n) (fn n))
show (FnShow3 fnStr fn) =
concat (map showOp [0, 1, 2, 3])
where showOp n = show (FnShow2 (fnStr ++ " " ++ show n) (fn n))
show (OpShow1 fnStr fn) =
concat (map showOp [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
where showOp n = show n ++ " " ++ fnStr ++ " = " ++ show (fn n) ++ "\n"
show (OpShow2 fnStr fn) =
concat (map showOp [0, 1, 2, 3])
where showOp n = show (FnShow1 (show n ++ " " ++ fnStr) (fn n))
data FnShow a = FnShow1 String (a -> a)
| FnShow2 String (a -> a -> a)
| FnShow3 String (a -> a -> a -> a)
| OpShow1 String (a -> a)
| OpShow2 String (a -> a -> a)
sqr x = x * x
abc a b c = a * b - c
main = do
print $ FnShow3 "abc" abc
print $ OpShow2 "+" (+)
print $ FnShow2 "mul" (*)
print $ FnShow1 "sqrt" sqrt
print $ OpShow1 "+ 2" (+2)
print $ FnShow1 "sqr" sqr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment