Haskell Flashcards
Instead of the + symbol, Haskell uses the symbol ANSWER for a string concatenation operator
.
++
The type of a string constant in Haskell by default is written ANSWER.
[Char]
In Haskell, you use the keyword ANSWER to collect related code into a similar scope.
module
In Haskell, if I define a function double x = x + x its type signature would be ANSWER.
(Num a ) => a -> a
In Haskell, instead of writing something like if x ==0 then 1 else fact (x-1)*x, you can write a series of lines starting with factorial 0 = 1. This second style is called ANSWER.
pattern matching
In Haskell, instead of writing something like if x==0 then 1 else fact (x-1) x, you can write a series of lines starting with | x > 1 = x factorial (x-a). This second style is called ANSWER.
using guards
In Haskell, instead of writing something like second x = head(tail(x)), you can write this without introducing the parameter x by using function composition. Doing that, you would define second by ANSWER.
second = head . tail
In Haskell, if I write (h:t) = [3 , 5 ,7], ANSWER is the value of h.
3
In Haskell, if I write (h:t) = [3, 5, 7], ANSWER is the value of t.
[5,7]
In Haskell, ANSWER is the output of zip [17…20] [10 , 8 ….4].
[(17,10),(18,8),(19,6), (20,4)]
In Haskell, ANSWER is the output of zip [20….17] [10,8…4]
[]
Default increment is 1 and zip only goes as far as shortest argument list
In Haskell, the anonymous function ANSWER causes the expression ‘map ANSWER [1,2,3]’ to produce [-4, -5, -6].
(\x-> - (x+3))
In Haskell, if we want to define a local named function inside a function definition, we use the keyword ANSWER.
where
In Haskell, the type signature of the function sum x y = x + y is ANSWER.
(Num a ) => a -> a -> a
In Haskell, given the definition sum x y = x + y, ANSWER is the value of that is produced by the expression (sum 3).
(\x -> 3 + x)
The way Haskell handles functions with more than one parameter is called ANSWER.
currying
In most languages, a function definition like f a b = a : (f (a + b) b) would result in an infinite recursion. However, in Haskell we can partially evaluate functions like this because Haskell is based on ANSWER.
lazy evaluation
Although Haskell is a statically typed language, we usually don’t need to write type declarations because Haskell uses ANSWER to handle the matter.
type inference
In Haskell, we can declare the type of a parameter to a function to be something specific like Num. However, we can also declare the type of a parameter to be something that could include many types like ListLike that supports the functions head and tail. We do this with a definition of ListLike that begins with the keyword ANSWER.
class
One of the three most significant parts of a monad is called ANSWER, which wraps up a function and puts it in the container.
return
One of the three most significant parts of a Haskell monad is called ANSWER, which unwraps up a function.
> > =
a bind function
In Haskell’s do notation for working with monads, assignment uses the ANSWER operator.
(left arrow)
Since Haskell doesn’t have traditional error handling mechanisms, by convention, people use the ANSWER monad to distinguish a valid return from an error return.
Maybe
This is similar to NaN’s usage in IEEE standard floating point arithmetic
Haskell, defining lists using a notation like [x*2 | x (left arrow) [3,4,5]] is called using ANSWER.
list comprehesions
In Haskell, [x*2 | x (left arrow) [3,4,5]] evaluates to ANSWER.
[6, 8, 10]