Skip to content

Instantly share code, notes, and snippets.

@rlorca
Created August 22, 2014 14:51
Show Gist options
  • Save rlorca/68ce0726786d82d1dde1 to your computer and use it in GitHub Desktop.
Save rlorca/68ce0726786d82d1dde1 to your computer and use it in GitHub Desktop.
Hello world in haskell
add a b = a + b
turboDrop n xs = if n <= 0 || null xs
then xs
else turboDrop (n -1)(tail xs)
fu = print "abc"
data Phones = Iphone | Htc_one
data DeviceInfo = Device Int String String
deviceId (Device id _ _) = id
deviceName (Device _ name _) = name
deviceSecret (Device _ _ secret) = secret
data Contact = Contact {
contactID :: Int,
contactName :: String,
contactAddress :: String
} deriving (Show)
splitLines [] = []
splitLines cs =
let (pre, suf) = break isLineTerminator cs
in pre : case suf of
('\r':'\n':rest) -> splitLines rest
('\r':rest) -> splitLines rest
('\n':rest) -> splitLines rest
_ -> []
isLineTerminator c = c == '\r' || c == '\n'
addHours amount total
| amount > 8 = "Total"
| amount < 8 && amount > 1 = "Partial"
| otherwise = "Just a break"
pluralise :: String -> [Int] -> [String]
pluralise word counts = map plural counts
where plural 0 = "no " ++ word ++ "s"
plural 1 = "one " ++ word
plural n = show n ++ " " ++ word ++ "s"
wordWithA (pref:rest)
| pref == 'a' = "true"
| otherwise = "false"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment