想像力こそが、すべてを変える。
学習リソース:
- 課程に基づいてLearn You a Haskell for Great Good (LYHGG) course link
- CIS 194: Introduction to Haskell (Spring 2013) course link
- Bitemyapp github
- 面白いスライドショーUniversity of Virginia CS 1501 Lectures Spring 2013 course link
- 1時間で学ぶ YouTube
Notes with Paul-ZQ Jan 19th @NUS-ALSET:
-
Haskell disallows multiple declaration of variable during a program's runtime. So in GHCi, you can assign different values to a variable name multiple times, but in a .hs program, the variable is tied to an expression/value.
-
A variable in Haskell is a name that is bound to the expression/value on the right, unlike in imperative programming's memory location abstraction.
-
Haskell does not have a
return
keyword, because a function is a single expression, not a sequence of statements. The value of the expression is the result of the function, and a function can be evaluated to be another partial function likepartialMod = mod x
. -
In imperative language, we can just write
if
without providing a branch forelse
. In Haskell, because we work with expression, anif
that does not haveelse
branch will not evaluate to a value if the predicate is False.
-- Haskell must provide an evaluated result for all branches
ifFunc x = if (x>10) then "Big number" else "Small number"
-- ifFunc 11 -> "Big number"
-
Haskell is lazy,
take 3 [1,2..]
will be[1,2,3]
-
:
operator takes in an item and return->
a function that takes in a list and->
return a list.
*Main> :t (:)
(:) :: a -> [a] -> [a]
*Main> (:) 1 [1]
[1,1]
- Pattern matching involving () and []. Since
:
's second input is a list type, so(x:xs)
actually means somex
concats to a listxs
.
someFunc :: [Char] -> Char
someFunc [] = '1'
someFunc (x:[]) = x
someFunc (x:xs) = head xs
-- in GHCi
*Main> someFunc "dettol"
'e'