Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pullrequest from Brazil - Learn Haskell #554

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
9de16d7
docs: Task 1 done
adrwtr Nov 1, 2022
e7b52c6
docs: Charter 1 - Task 2 done
adrwtr Nov 1, 2022
1dc7fce
docs: Charter 1 - Task 3 done
adrwtr Nov 1, 2022
d89747d
docs: Charter 1 - Task 3 and 4 done
adrwtr Nov 1, 2022
1d04f0d
docs: Charter 1 - Task 5, 6, 7 and 8
adrwtr Nov 1, 2022
320bc4d
docs: Charter 1 - Task 9 and boss
adrwtr Nov 1, 2022
9a1e01e
docs: Charter 2 - Task 1 in comments
adrwtr Nov 2, 2022
c9ca63b
docs: Charter 2 - Task 2 in comments
adrwtr Nov 2, 2022
e3fbc7a
docs: Charter 2 - Task 3, 4 and 5
adrwtr Nov 2, 2022
0108694
docs: Charter 2 - Task 6 and 7
adrwtr Nov 2, 2022
4ff6264
docs: Charter 2 - Task 8 and 9
adrwtr Nov 2, 2022
0543601
docs: Charter 2 - Task 10
adrwtr Nov 2, 2022
bc1d976
docs: Charter 2 - Task 11 and 12
adrwtr Nov 3, 2022
29df2f6
fix: Charter 1 - review solutions
adrwtr Nov 19, 2022
e6b6a89
fix: run unit test to test and fix
adrwtr Nov 22, 2022
c059035
fix: run unit test to test and fix - from charter 2
adrwtr Nov 22, 2022
ed58cee
doc: charter 2 take
adrwtr Nov 22, 2022
bd324a9
feat: charter 3 task 1
adrwtr Nov 27, 2022
522bc30
feat: task 4 - incomplete
adrwtr Dec 5, 2022
372a36a
tentativa de resolucao
adrwtr Dec 9, 2022
af76b02
wip: task 4 - very hard
Dec 9, 2022
ee29b5a
feat provocation of vrom911 for divMod - hard stuff
adrwtr Jan 6, 2023
aed9e03
fix: rewind function now use cons :
adrwtr Jan 6, 2023
ee075a6
feat task 7 - Gold and List
adrwtr Jan 7, 2023
3eb3219
feat task 8 days of week
adrwtr Jan 7, 2023
189f7d4
wip - work in progress charter 4
adrwtr Jan 9, 2023
fd7d1ad
Charter 3 complete
Jan 12, 2023
f44746a
feat: Chapter 4 - Task 3 - complete
Jan 12, 2023
690374f
feat: Chapter 4 - task 4 done!
Jan 16, 2023
78e2e12
feat: Chapter4 - task 5
Jan 16, 2023
c1c04bd
feat: Chapter4 - task 6 and 7 done
Jan 18, 2023
178302c
feat: Chapter 4 - task 8
Jan 19, 2023
ae27249
wip: final boss chapter 4
Jan 19, 2023
461855a
wip: final boss chapter 4
Jan 19, 2023
5de4768
feat: Chapter 4 completed
Jan 20, 2023
515ae94
feat: Chapter 4 completed
Jan 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -54,3 +54,4 @@ TAGS
# other
.DS_Store
.env
Dockerfile
89 changes: 59 additions & 30 deletions src/Chapter1.hs
Original file line number Diff line number Diff line change
@@ -209,31 +209,31 @@ So, the output in this example means that 'False' has type 'Bool'.
> Try to guess first and then compare your expectations with GHCi output

>>> :t True
<INSERT THE RESULT INSTEAD OF THE TEXT>
True :: Bool
>>> :t 'a'
<INSERT THE RESULT INSTEAD OF THE TEXT>
'a' :: Char
>>> :t 42
<INSERT THE RESULT INSTEAD OF THE TEXT>
42 :: Num a => a

A pair of boolean and char:
>>> :t (True, 'x')
<INSERT THE RESULT INSTEAD OF THE TEXT>
(True, 'x') :: (Bool, Char)

Boolean negation:
>>> :t not
<INSERT THE RESULT INSTEAD OF THE TEXT>
not :: Bool -> Bool

Boolean 'and' operator:
>>> :t (&&)
<INSERT THE RESULT INSTEAD OF THE TEXT>
(&&) :: Bool -> Bool -> Bool

Addition of two numbers:
>>> :t (+)
<INSERT THE RESULT INSTEAD OF THE TEXT>
(+) :: Num a => a -> a -> a

Maximum of two values:
>>> :t max
<INSERT THE RESULT INSTEAD OF THE TEXT>
max :: Ord a => a -> a -> a

You might not understand each type at this moment, but don't worry! You've only
started your Haskell journey. Types will become your friends soon.
@@ -301,43 +301,43 @@ expressions in GHCi
functions and operators first. Remember this from the previous task? ;)

>>> 1 + 2
<INSERT THE RESULT INSTEAD OF THE TEXT>
3

>>> 10 - 15
<INSERT THE RESULT INSTEAD OF THE TEXT>
-5

>>> 10 - (-5) -- negative constants require ()
<INSERT THE RESULT INSTEAD OF THE TEXT>
15

>>> (3 + 5) < 10
<INSERT THE RESULT INSTEAD OF THE TEXT>
True

>>> True && False
<INSERT THE RESULT INSTEAD OF THE TEXT>
False

>>> 10 < 20 || 20 < 5
<INSERT THE RESULT INSTEAD OF THE TEXT>
True

>>> 2 ^ 10 -- power
<INSERT THE RESULT INSTEAD OF THE TEXT>
1024

>>> not False
<INSERT THE RESULT INSTEAD OF THE TEXT>
True

>>> div 20 3 -- integral division
<INSERT THE RESULT INSTEAD OF THE TEXT>
6

>>> mod 20 3 -- integral division remainder
<INSERT THE RESULT INSTEAD OF THE TEXT>
2

>>> max 4 10
<INSERT THE RESULT INSTEAD OF THE TEXT>
10

>>> min 5 (max 1 2)
<INSERT THE RESULT INSTEAD OF THE TEXT>
2

>>> max (min 1 10) (min 5 7)
<INSERT THE RESULT INSTEAD OF THE TEXT>
5

Because Haskell is a __statically-typed__ language, you see an error each time
you try to mix values of different types in situations where you are not
@@ -428,7 +428,7 @@ task is to specify the type of this function.
>>> squareSum 3 4
49
-}

squareSum :: Int -> Int -> Int
squareSum x y = (x + y) * (x + y)


@@ -449,7 +449,7 @@ Implement the function that takes an integer value and returns the next 'Int'.
function body with the proper implementation.
-}
next :: Int -> Int
next x = error "next: not implemented!"
next x = x + 1

{- |
After you've implemented the function (or even during the implementation), you
@@ -490,7 +490,8 @@ Implement a function that returns the last digit of a given number.
whether it works for you!
-}
-- DON'T FORGET TO SPECIFY THE TYPE IN HERE
lastDigit n = error "lastDigit: Not implemented!"
lastDigit :: Int -> Int
lastDigit n = mod (abs n) 10


{- |
@@ -520,7 +521,7 @@ branches because it is an expression and it must always return some value.
satisfying the check will be returned and, therefore, evaluated.
-}
closestToZero :: Int -> Int -> Int
closestToZero x y = error "closestToZero: not implemented!"
closestToZero x y = if abs x < abs y then x else y


{- |
@@ -553,8 +554,13 @@ value after "=" where the condition is true.

Casual reminder about adding top-level type signatures for all functions :)
-}

mid x y z = error "mid: not implemented!"
mid :: Int -> Int -> Int -> Int
mid x y z
| x < y && x < z && y < z = y
| z < x && z < y && x < y = x
| z < x && z < y && y < x = y
| y < x && y < z && x < z = x
| otherwise = z

{- |
=⚔️= Task 8
@@ -568,7 +574,14 @@ True
>>> isVowel 'x'
False
-}
isVowel c = error "isVowel: not implemented!"
isVowel :: Char -> Bool
isVowel c
| c == 'a' = True
| c == 'e' = True
| c == 'i' = True
| c == 'o' = True
| c == 'u' = True
| otherwise = False


{- |
@@ -632,8 +645,21 @@ Try to introduce variables in this task (either with let-in or where) to avoid
specifying complex expressions.
-}

sumLast2 n = error "sumLast2: Not implemented!"
sumLast2 :: Int -> Int
sumLast2 n = mod10 (div10 n) + mod10 n
where
div10 :: Int -> Int
div10 x = div (abs x) 10

mod10 :: Int -> Int
mod10 x = mod (abs x) 10

sumLast2' :: (Integral a, Num a) => a -> a
sumLast2' n = mdiv10 + mod1
where
mdiv10 = mod c 10
mod1 = d
(c, d) = divMod (abs n) 10

{- |
=💣= Task 10*
@@ -653,7 +679,10 @@ You need to use recursion in this task. Feel free to return to it later, if you
aren't ready for this boss yet!
-}

firstDigit n = error "firstDigit: Not implemented!"
firstDigit :: Int -> Int
firstDigit n = if abs n < 10
then abs n
else firstDigit (abs n `div` 10)


{-
Loading