Skip to content

Instantly share code, notes, and snippets.

@vvv
vvv / OrdEq.hs
Created September 7, 2017 10:54 — forked from mssawant/ordeq.hs
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"
@vvv
vvv / misc.hs
Last active August 24, 2017 16:50 — forked from mssawant/misc.hs
Haskell exercise
{-- 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')
--}
listsum :: Num a => [a] -> a
listsum [] = 0
listsum (x:xs) = x + listsum xs
main :: IO ()
main = print $ listsum [1..5]