forked from thoughtbot/guides
-
Notifications
You must be signed in to change notification settings - Fork 0
/
haskell.hs
91 lines (73 loc) · 1.62 KB
/
haskell.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
module Haskell
( SomeType(..)
, someFunction
, anotherFunction
) where
import Control.Monad.State (state, evalState)
import Data.List (foldl')
import Data.Text (Text)
import qualified Data.Map as M
import qualified Data.Text as T
import Database.Persistent (runSql)
import Yesod
import Yesod.Auth (requireAuthId, maybeAuthId)
import Foundation
import Settings
data Colors = Red | Blue | Green
data HTTPException
= NotFound
| NotAuthorized
| InternalServerError
| Whatever
| YouGetTheIdea
data SomeType = SomeType
{ accessorOne :: String
, accessorTwo :: String
, accessorThree :: String
} deriving Show
someType :: SomeType
someType = SomeType
{ accessorOne = "foo"
, accessorTwo = "bar"
, accessorThree = theThird
}
where
theThird :: String
theThird = "bar"
myFunction :: Show a
=> a
-> a
-> (a -> b)
-> (b, b)
myFunction = -- ...
aList :: [String]
aList =
[ one
, two
, three
]
aShortFunction = let x = 7 in x + 2
aLongerFunction =
let x = 42
y = 57
z = 57
in sum $ [x, y, z]
aCasedFunction x =
case x of
Just y -> y
Nothing -> 0
aShortIf x = if x then y else z
aLongIf xs =
if take 10 xs == [1..10]
then drop 2 $ reverse xs
else []
lineBreaks = take 3 -- prefix
. reverse . drop 1 . reverse . drop 1 -- strip
. map upcase -- scream
main :: IO ()
main = do
let x = getX
andY = getY
a <- getA
andB <- getB
return $ x + andY + a + andB