Solve first task
This commit is contained in:
parent
3bb0b1ead0
commit
0649df9598
2 changed files with 21 additions and 14 deletions
|
@ -87,20 +87,23 @@ floatSevenByThree = 7 / 3
|
|||
Check your solutions with the REPL.
|
||||
|
||||
|
||||
x :: Integer
|
||||
x = 2 ^ 3
|
||||
>>> x :: Integer = 2 ^ 3
|
||||
|
||||
y :: Float
|
||||
y = 2.0 ^ 3
|
||||
>>> y :: Float = 2.0 ^ 3
|
||||
|
||||
a :: ?
|
||||
a = x + 5
|
||||
>>> a :: Integer = x + 5
|
||||
|
||||
b :: ?
|
||||
b = y/2
|
||||
b :: Float
|
||||
>>> b = y/2
|
||||
>>> :t b
|
||||
b :: Float
|
||||
|
||||
c :: ?
|
||||
c = y `div` 3
|
||||
c :: Error
|
||||
>>> c = y `div` 3
|
||||
>>> :t c
|
||||
No instance for (Integral Float) arising from a use of `div'
|
||||
In the expression: y `div` 3
|
||||
In an equation for `c': c = y `div` 3
|
||||
|
||||
-}
|
||||
|
||||
|
@ -179,7 +182,7 @@ aListOfInts = [ 1, 2, 3 ]
|
|||
{- Exercise
|
||||
Fill out the type, check your solutions with the REPL.
|
||||
|
||||
friendGroups :: ?
|
||||
friendGroups :: [[String]]
|
||||
friendGroups =
|
||||
[ ["Peter", "Anna", "Roman", "Laura"]
|
||||
, ["Anna","Reto"]
|
||||
|
@ -215,11 +218,15 @@ lessThanPairs = [ (x,y)
|
|||
all square numbers between 1 and 100.
|
||||
-}
|
||||
squares :: [Integer]
|
||||
squares = error "fixme"
|
||||
squares = [ x^2 | x <- [1..(floor (sqrt 100))]]
|
||||
-- >>> squares
|
||||
-- [1,4,9,16,25,36,49,64,81,100]
|
||||
|
||||
{- Exercise
|
||||
Use list comprehension to declare a list that contains
|
||||
all odd square numbers between 1 and 100.
|
||||
-}
|
||||
oddSquares :: [Integer]
|
||||
oddSquares = error "fixme"
|
||||
oddSquares = [ x^2 | x <- [1..(floor (sqrt 100))], odd (x^2)]
|
||||
-- >>> oddSquares
|
||||
-- [1,9,25,49,81]
|
||||
|
|
Loading…
Reference in a new issue