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

Completed Chapter 2 #545

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
4b14396
completed Task 1
yebowhatsay Oct 14, 2022
25952b6
completed Task 4
yebowhatsay Oct 14, 2022
fda7f4f
completed Task 6
yebowhatsay Oct 14, 2022
49e35f0
completed tasks in Chapter 1
yebowhatsay Oct 14, 2022
87ddeee
fixed a few bugs
yebowhatsay Oct 14, 2022
6a513c5
fixed firstDigit negative num bug
yebowhatsay Oct 14, 2022
0e79911
fixed redundant brackets
yebowhatsay Oct 14, 2022
bbee129
removed incorrect, commented closestToZero
yebowhatsay Oct 14, 2022
07b9b42
using divMod for sumLast2
yebowhatsay Oct 14, 2022
8cc6ed5
tests pass in Chapter1
yebowhatsay Oct 15, 2022
5e61213
added ghcup-list to Makefile
yebowhatsay Oct 15, 2022
48cb30c
improved mid function
yebowhatsay Oct 15, 2022
11833e1
completed Task1
yebowhatsay Oct 15, 2022
e831b30
extended tests for Chapter1 pass
yebowhatsay Oct 15, 2022
50594e5
completed Task 3:Chapter2
yebowhatsay Oct 16, 2022
7540e0d
completed Task 4:Chapter2
yebowhatsay Oct 16, 2022
c8c8147
completed Task 5:Chapter2
yebowhatsay Oct 16, 2022
b3671e6
completed Task 6:Chapter2
yebowhatsay Oct 16, 2022
13b9694
completed Task 7:Chapter2
yebowhatsay Oct 16, 2022
1c61d62
completed Task 8:Chapter2
yebowhatsay Oct 16, 2022
6f7b0b2
completed Task 9:Chapter2
yebowhatsay Oct 16, 2022
7f7ea4d
completed Task 10:Chapter2
yebowhatsay Oct 16, 2022
6cba85f
completed Task 11:Chapter2
yebowhatsay Oct 16, 2022
d7363c5
completed Task 12:Chapter2
yebowhatsay Oct 16, 2022
da81cae
Chapter2: all tests pass!
yebowhatsay Oct 16, 2022
03720de
completed Task1: Chapter3
Oct 17, 2022
ed6bb58
wrote the monster, knight game. woohoo
yebowhatsay Oct 17, 2022
c402998
changed knight win proclamation
yebowhatsay Oct 17, 2022
d2ec197
minor comments, Chapter 3
Oct 18, 2022
e7e9442
completed Task 3, Chapter 3
Oct 18, 2022
f4a76f1
completed Task 5: Chapter 3
yebowhatsay Oct 18, 2022
96bae81
completed Task 6: Chapter 3
yebowhatsay Oct 18, 2022
9a7589c
completed Task 7 : Chapter 3
yebowhatsay Oct 20, 2022
8fea446
completed Task 8: Chapter 3
yebowhatsay Oct 23, 2022
1da351b
working on Task 9: Chapter 3
yebowhatsay Oct 23, 2022
0c4dffb
move loop working
Oct 25, 2022
a26c6b5
functioning Task9
Oct 25, 2022
85200a2
Completed Chapter 3
yebowhatsay Oct 25, 2022
2416836
completed Task2: Chapter 4
yebowhatsay Oct 25, 2022
d857b87
updated Task 9, Chapter 3
Oct 26, 2022
f60c32e
reached Monads!
yebowhatsay Oct 28, 2022
b5380f9
completed Task8: Chapter 4. tests passing
Oct 29, 2022
3d4d5e4
working on the last task
yebowhatsay Oct 29, 2022
e38d4f2
completed Chapter 4, all tests pass
yebowhatsay Oct 30, 2022
59ad927
added return to Monad
Oct 31, 2022
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
11 changes: 11 additions & 0 deletions CHANGELOG.md.save0
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changelog

`learn4haskell` uses [PVP Versioning][1].
The changelog is available [on GitHub][2].

## 0.0.0.0

* Initially created.

[1]: https://pvp.haskell.org
[2]: https://github.com/kowainik/learn4haskell/releases
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@ test-chapter4-basic:
.PHONY: test-all
test-all:
cabal test all --enable-tests --test-show-details=direct

ghcup-list:
ghcup list -c set
4 changes: 4 additions & 0 deletions app/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Main where

main :: IO ()
main = putStrLn "Hello, Haskell!"
37 changes: 37 additions & 0 deletions learn4haskell-yebowhatsay.cabal.xxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
cabal-version: 2.4
name: learn4haskell-yebowhatsay
version: 0.1.0.0

-- A short (one-line) description of the package.
-- synopsis:

-- A longer description of the package.
-- description:

-- A URL where users can report bugs.
-- bug-reports:

-- The license under which the package is released.
-- license:
author: yebowhatsay
maintainer: [email protected]

-- A copyright notice.
-- copyright:
-- category:
extra-source-files:
README.md
CHANGELOG.md

executable learn4haskell-yebowhatsay
main-is: Main.hs

-- Modules included in this executable, other than Main.
-- other-modules:

-- LANGUAGE extensions used by modules in this package.
-- other-extensions:
build-depends: base
--^>=4.13.0.0
hs-source-dirs: app
default-language: Haskell2010
6 changes: 4 additions & 2 deletions learn4haskell.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ source-repository head
location: https://github.com/kowainik/learn4haskell.git

common common-options
build-depends: base ^>= 4.14.0.0
build-depends: base
--^>= 4.14.0.0

ghc-options: -Wall
-Wcompat
Expand All @@ -42,7 +43,8 @@ common common-options
common common-doctest
import: common-options
hs-source-dirs: test
build-depends: doctest ^>= 0.17
build-depends: doctest
--^>= 0.17
ghc-options: -threaded

library
Expand Down
89 changes: 59 additions & 30 deletions src/Chapter1.hs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Modules should have the same name as the corresponding file with
the `.hs` extension.
-}
module Chapter1 where
import Data.List

{- |
In Haskell, we have __expressions__. Expressions can be represented by some
Expand Down Expand Up @@ -209,31 +210,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 p => p

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.
Expand Down Expand Up @@ -301,43 +302,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
Expand Down Expand Up @@ -429,6 +430,7 @@ task is to specify the type of this function.
49
-}

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


Expand All @@ -449,7 +451,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
Expand Down Expand Up @@ -490,9 +492,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 :: Integral a => a -> a
lastDigit n = mod (abs n) 10
{- |
=⚔️= Task 6

Expand Down Expand Up @@ -520,7 +521,9 @@ 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


{- |
Expand Down Expand Up @@ -554,7 +557,10 @@ 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 :: Integral a => a -> a -> a -> a
mid x y z = (sort [x, y, z]) !! 1

{- |
=⚔️= Task 8
Expand All @@ -568,7 +574,15 @@ 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



{- |
Expand Down Expand Up @@ -632,7 +646,16 @@ 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 = let a = mod (abs n) 100
-- b = mod a 10
-- c = div a 10
-- in
-- c + b
sumLast2 n = x + y
where a = abs n
(_, b) = divMod a 100
(x, y) = divMod b 10


{- |
Expand All @@ -653,7 +676,13 @@ 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
| y < 10 = y
| x < 10 = x
| otherwise = firstDigit x
where y = abs n
x = div y 10


{-
Expand Down
Loading