This file contains 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
import Data.Foldable (foldl') | |
import Debug.Trace (trace) | |
prnEqual :: (Eq a) => a -> a -> IO () | |
prnEqual a b = if a == b then print "True" else print "False" | |
-- Note the absence of parentheses around `Eq a` and having exactly one `print`. | |
prnEqual' :: Eq a => a -> a -> IO () | |
prnEqual' a b = print $ if a == b then "True" else "False" |
This file contains 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
{-- XXX Your definition of `checkChar` is okay, but the abstraction itself | |
-- is very odd. It is fine as an exercise of using "do" notation and | |
-- `return`. In real code though explicit statements are both short and | |
-- expressive (see lines 21-22). | |
checkChar :: IO Bool | |
checkChar = do | |
c <- getChar | |
return (c == 'y') | |
--} |
This file contains 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
listsum :: Num a => [a] -> a | |
listsum [] = 0 | |
listsum (x:xs) = x + listsum xs | |
main :: IO () | |
main = print $ listsum [1..5] |