Last active
August 29, 2015 14:04
-
-
Save fronx/832f081a6c7620872130 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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