Skip to content

Instantly share code, notes, and snippets.

@shapr
Created June 27, 2015 22:56
Show Gist options
  • Save shapr/56bba448d905e25ba627 to your computer and use it in GitHub Desktop.
Save shapr/56bba448d905e25ba627 to your computer and use it in GitHub Desktop.
HaskellDemo.hs
module HaskellDemo where
somenumber :: Double
somenumber = 1
somestring = "foo"
somelist :: [Double]
somelist = [1,2,3.0]
type Name = String
type Age = Int
data Person = PersonConstructor Name Age deriving Show
-- whoDat (PersonConstructor who when) = who ++ " is probably " ++ when ++ " years old."
data Container a = Constructor a deriving Show
data Season = Winter | Spring | Summer | Fall deriving (Eq,Ord,Enum,Show,Bounded)
class Temperature a where
isHot :: a -> Bool
instance Temperature Season where
isHot Summer = True
isHot Fall = True
isHot _ = False
mylength [] = 0
mylength (x:xs) = 1 + mylength xs
-- mylength foo
-- | foo == [] = 0
-- | otherwise = 1 + tail foo
-- mylength = case foo of
-- [] -> 0
-- _ -> 1 + mylength (tail foo)
-- myfoo = if True then 1 else 2
fibs = 1:1: zipWith (+) fibs (tail fibs)
ones = 1:ones
-- addOne :: Int -> Int
-- addOne n = n + 1
addTwo :: Int -> (Int -> Int)
addTwo x y = x + y
addOne n = addTwo 1 n
-- data CalcState = CalcState Int
-- calcadd n1 n2 m = n1 + n2
-- calcmin n1 n2 m = n1 - n2
-- result :: Float
-- result = calcadd 1 (calcmin 5 2)
-- data Fail a = Fail | Thing a
-- data Maybe a = Nothing | Just a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment