kowainik / learn4haskell Goto Github PK
View Code? Open in Web Editor NEWπ©βπ« π¨βπ« Learn Haskell basics in 4 pull requests
Home Page: https://kowainik.github.io/projects/learn4haskell
License: Mozilla Public License 2.0
π©βπ« π¨βπ« Learn Haskell basics in 4 pull requests
Home Page: https://kowainik.github.io/projects/learn4haskell
License: Mozilla Public License 2.0
IN THE README THERE IS A SPELLING ERROR #98
CHANGED "ETA REDUCTION" TO "BETA REDUCTION"
See haskell/happy#180 and
β make test-chapter2
cabal test doctest-chapter2 --enable-tests --test-show-details=direct
Build profile: -w ghc-8.10.1 -O1
In order, the following will be built (use -v for more details):
- learn4haskell-0.0.0.0 (test:doctest-chapter2) (first run)
Preprocessing test suite 'doctest-chapter2' for learn4haskell-0.0.0.0..
Building test suite 'doctest-chapter2' for learn4haskell-0.0.0.0..
Running 1 test suites...
Test suite doctest-chapter2: RUNNING...
Examples: 54 Tried: 54 Errors: 0 Failures: 0
Test suite doctest-chapter2: PASS
Test suite logged to:
/Users/xxx/code/learn4haskell/dist-newstyle/build/x86_64-osx/ghc-8.10.1/learn4haskell-0.0.0.0/t/doctest-chapter2/test/learn4haskell-0.0.0.0-doctest-chapter2.log
1 of 1 test suites (1 of 1 test cases) passed.
cabal run learn4haskell-test --enable-tests -- -m "Chapter2"
Build profile: -w ghc-8.10.1 -O1
In order, the following will be built (use -v for more details):
- happy-1.20.0 (exe:happy) (requires build)
- pretty-show-1.10 (lib) (requires build)
- hedgehog-1.0.4 (lib) (requires build)
- hspec-hedgehog-0.0.1.2 (lib) (requires build)
- learn4haskell-0.0.0.0 (test:learn4haskell-test) (first run)
Starting happy-1.20.0 (exe:happy)
Building happy-1.20.0 (exe:happy)
Failed to build exe:happy from happy-1.20.0.
Build log ( /Users/xxx/.cabal/logs/ghc-8.10.1/hppy-1.20.0-9ac48e58.log ):
Configuring executable 'happy' for happy-1.20.0..
Preprocessing executable 'happy' for happy-1.20.0..
Building executable 'happy' for happy-1.20.0..
[ 1 of 19] Compiling AbsSyn ( src/AbsSyn.lhs, dist/build/happy/happy-tmp/AbsSyn.o )
[ 2 of 19] Compiling GenUtils ( src/GenUtils.lhs, dist/build/happy/happy-tmp/GenUtils.o )
[ 3 of 19] Compiling NameSet ( src/NameSet.hs, dist/build/happy/happy-tmp/NameSet.o )
[ 4 of 19] Compiling ParamRules ( src/ParamRules.hs, dist/build/happy/happy-tmp/ParamRules.o )
[ 5 of 19] Compiling ParseMonad ( src/ParseMonad.hs, dist/build/happy/happy-tmp/ParseMonad.o )
[ 6 of 19] Compiling Lexer ( src/Lexer.lhs, dist/build/happy/happy-tmp/Lexer.o )
[ 7 of 19] Compiling AttrGrammar ( src/AttrGrammar.lhs, dist/build/happy/happy-tmp/AttrGrammar.o )
[ 8 of 19] Compiling AttrGrammarParser ( src/AttrGrammarParser.hs, dist/build/happy/happy-tmp/AttrGrammarParser.o )
[ 9 of 19] Compiling Grammar ( src/Grammar.lhs, dist/build/happy/happy-tmp/Grammar.o )
[10 of 19] Compiling LALR ( src/LALR.lhs, dist/build/happy/happy-tmp/LALR.o )
[11 of 19] Compiling First ( src/First.lhs, dist/build/happy/happy-tmp/First.o )
[12 of 19] Compiling Parser ( src/Parser.hs, dist/build/happy/happy-tmp/Parser.o )
[13 of 19] Compiling Paths_happy ( dist/build/happy/autogen/Paths_happy.hs, dist/build/happy/happy-tmp/Paths_happy.o )
[14 of 19] Compiling Info ( src/Info.lhs, dist/build/happy/happy-tmp/Info.o )
[15 of 19] Compiling PrettyGrammar ( src/PrettyGrammar.hs, dist/build/happy/happy-tmp/PrettyGrammar.o )
[16 of 19] Compiling ProduceGLRCode ( src/ProduceGLRCode.lhs, dist/build/happy/happy-tmp/ProduceGLRCode.o )
[17 of 19] Compiling Target ( src/Target.lhs, dist/build/happy/happy-tmp/Target.o )
[18 of 19] Compiling ProduceCode ( src/ProduceCode.lhs, dist/build/happy/happy-tmp/ProduceCode.o )
[19 of 19] Compiling Main ( src/Main.lhs, dist/build/happy/happy-tmp/Main.o )
Linking dist/build/happy/happy ...
Undefined symbols for architecture x86_64:
"___darwin_check_fd_set_overflow", referenced from:
_awaitEvent in libHSrts.a(Select.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
`clang' failed in phase `Linker'. (Exit code: 1)
cabal: Failed to build exe:happy from happy-1.20.0 (which is required by
test:learn4haskell-test from learn4haskell-0.0.0.0). See the build log above
for details.
make: *** [test-chapter2] Error 1
There's a minor typo in chapter 1's task 2:
ghci> :t add
Add :: Int -> Int -> Int
Notice the uppercase 'A' in Add
. It should be add
.
Each one to check the corresponding tests
I'm running the code on branch that is synced with your master and get this during make test-chapter1
and make test-chapter2
:
test/Test/Chapter1.hs:72:40: error:
β’ Couldn't match expected type βIntβ with actual type βIntegerβ
β’ In the second argument of β(===)β, namely
β(lastDigit (reverseInt x) :: Int)β
In a stmt of a 'do' block:
(firstDigit x :: Int) === (lastDigit (reverseInt x) :: Int)
In the second argument of β($)β, namely
βdo x <- forAll $ Gen.int (Range.linear (- 200) 200)
(firstDigit x :: Int) === (lastDigit (reverseInt x) :: Int)β
|
72 | (firstDigit x :: Int) === (lastDigit (reverseInt x) :: Int)
| ^^^^^^^^^^^^^^^^^^^^^^^^
test/Test/Chapter1.hs:72:51: error:
β’ Couldn't match expected type βIntegerβ with actual type βIntβ
β’ In the first argument of βlastDigitβ, namely β(reverseInt x)β
In the second argument of β(===)β, namely
β(lastDigit (reverseInt x) :: Int)β
In a stmt of a 'do' block:
(firstDigit x :: Int) === (lastDigit (reverseInt x) :: Int)
|
72 | (firstDigit x :: Int) === (lastDigit (reverseInt x) :: Int)
| ^^^^^^^^^^^^
make: *** [Makefile:22: test-chapter2] Error 1
My implementation of the method seems valid (tested manually both outputs & types):
firstDigit :: Int -> Int
firstDigit n
| n < 0 = firstDigit (-n)
| n < 10 = n
| otherwise = firstDigit $ n `div` 10
It seems like, despite the local tests passing for my chapter 1 solutions, the Github actions are failing.
Here's the more detailed log.
It looks like there's a typo in README.md: "...people are contributing to projects within the communities they are
boiling in." Are you sure you wanted to use the verb "boil" here? I mean, I can imagine that tempers can flare up sometimes in programming communities, but I never thought the temperature would reach boiling point ;)
See relevant danielboros#1 (comment)
This could be the GH Action which will generate the pdf when all of the CI checks are green in the main
.
Hi, guys, greetings!
This is a very confusing part of typeclass to me.
I can define an instance for "Secret e a", which the "Trap e" is being fixed.
But I can't figure out the way to also define a Functor instance for the first type variable, which is the value "Trap e" of "Secret e a"
For example:
data Secret e a
= Trap e
| Reward a
deriving (Show, Eq)
-- This one for the value "Reward a" works.
-- instance Functor (Secret e) where
-- fmap :: (a -> b) -> Secret e a -> Secret e b
-- fmap _ (Trap a) = Trap a
-- fmap f (Reward a) = Reward (f a)
But how do I possibly have the value "Trap e" also to work for fmap, is it for some reason that such cases are not necessary?
In the description of lambda functions in Chapter2.hs it says "For example, we can easily append number 3", but this should be "add number three".
No tests for functor and applicative instances for List type.
I have Haskell already installed on my system, and that includes stack
but not cabal
.
So, in order to run the tests for this course, I installed ghcup
in Docker, then cabal, and ran the tests there.
Would a PR with instructions for how to do this be useful? Or a Dockerfile
even?
Hello,
Just begon with this nice challenge and run into something I do not understand
I have this code :
>>> :t True
True::Bool
and I see a test error which said this :
Test suite doctest-chapter1: RUNNING...
src/Chapter1.hs:211: failure in expression `:t True'
expected: True::Bool
but got: True :: Bool
^
```
what is wrong here. For me bith looks the same ?
Chapter3 says:
As you can see, both monster and knight have similar characteristics, but they
also have some differences. So it is possible to describe their common
properties using typeclasses, but they are different data types in the end.
Do typeclasses describe their common properties (e.g. health) or the common actions that can be taken on them (e.g. fight)?
I have solutions for Chapter1.
Test suite doctest-chapter1: RUNNING...
src/Chapter1.hs:298: failure in expression `1 + 2'
expected: 3
it :: Num a => a
but got: 3
^
but I have in code:
>>> 1 + 2
3
it :: Num a => a
>>> 10 - 15
Something wrong...
The following assertion in Chapter 4, Task 8 is incorrect, it should be Nothing
as well
learn4haskell/test/Test/Chapter4.hs
Line 59 in 0bdad6f
Thank you @vrom911 and @chshersh for this fun course! Just the right difficulty level for a 'confidence building' break from Haskell Programming From First Principles.
I'm finding myself searching through PRs to see solutions - sometimes I need a hint, and sometimes I just want to see other solutions, or what you've said to others.
Instead of you reviewing many PRs with the same basic solutions, many of us could review our own if there was a set of solutions provided - maybe even just taken from a PR you thought had the best solutions?
Thank you again for all the work you've put into this.
length (duplicate xs) = 2 * (lenght xs)
rewind
= reverse
Dumb question, guys.
Somehow I'm unable to open the last pull request.
On my forked repo I can see the latest commit, with Chapter 4 solutions. Then, if I open the "create a pull request" link I can't see the usual embedded editor from which I can add a description and then open the pull request.
Any ideas? Thanks
@vrom911 @chshersh Some clarifications needed please ?
Prepare to defend the honour of our kingdom! A monster attacks our brave knight.
Help him to fight this creature!
Define data types for Knights and Monsters, and write the "fight" function.
Both a knight and a monster have the following properties:
β¦ Health (the number of health points)
β¦ Attack (the number of attack units)
β¦ Gold (the number of coins)
When a monster fights a knight, the knight hits first, and the monster hits back
only if it survives (health is bigger than zero). A hit decreases the amount of
health by the number represented in the "attack" field.
Implement the "fight" function, that takes a monster and a knight, performs the
fight following the above rules and returns the amount of gold the knight has
after the fight. The battle has the following possible outcomes:
β Knight wins and takes the loot from the monster and adds it to their own
earned treasure
β Monster defeats the knight. In that case return -1
β Neither the knight nor the monster wins. On such an occasion, the knight
doesn't earn any money and keeps what they had before.
It seems the question is not really clear, should this be interpreted as a fight between knight and monster with multiple rounds
or a single round ?
Based on this commit from a PR and many other PR's which are similar and accepted as an answer. I don't understand, how can the below function be true based on the following data:
balrog :: Monster
balrog = Monster {
monsterHealth = 97,
monsterAttack = 5,
monsterGold = 70
}
arthur :: Knight
arthur = Knight {
knightHealth = 93,
knightAttack = 7,
knightGold = 82
}
fight (Knight _ knightHealth knightAttack knightGold) (Monster monsterHealth monsterAttack monsterGold)
| knightAttack >= monsterHealth = knightGold + monsterGold
| monsterAttack >= knightHealth = -1
| otherwise = knightGold
Based on the first condition knightAttack >= monsterHealth
will be false, hence Arthur loses, but in fact if the fight goes on until either is dead (health 0) then Arthur would win.
Mention where we need to be more careful when working with Int
s:
Neither DoctestChapter3.hs
nor test/Test/Chapter3.hs
contain any tests.
Hi!
I am trying the course, after cloning the repo first thing I do is to run a test.
$make test-chapter1-basic
cabal test doctest-chapter1 --enable-tests --test-show-details=direct
Resolving dependencies...
cabal: Could not resolve dependencies:
[__0] trying: learn4haskell-0.0.0.0 (user goal)
[__1] next goal: base (dependency of learn4haskell)
[__1] rejecting: base-4.15.1.0/installed-4.15.1.0 (conflict: learn4haskell => base^>=4.14.0.0)
I am using:
cabal-install version 3.4.0.0
compiled using version 3.4.1.0 of the Cabal library
The Glorious Glasgow Haskell Compilation System, version 9.0.2
which I have installed and configured following this guide
I have tried modifying learn4haskell.cabal and removing version constraint, which resulted in a failure in a different dependency.
Please comment on possible solutions or workarounds. Thank you
Hi, first thanks for making this kowainik!
I'm getting some weird output from the tests:
src/Chapter1.hs:221: failure in expression `:t (&&)'
expected: (&&) :: Bool -> Boolean -> Bool
but got: (&&) :: Bool -> Bool -> Bool
Looks to me like the "expected" (which is my incorrect answer) is switched with "but got".
Also, the output seems to jump around, going from complaining about line 221 to line 305, even though there are many tests between there:
Test suite doctest-chapter1: RUNNING...
src/Chapter1.hs:221: failure in expression `:t (&&)'
expected: (&&) :: Bool -> Boolean -> Bool
but got: (&&) :: Bool -> Bool -> Bool
^
src/Chapter1.hs:305: failure in expression `(3 + 5) < 10'
expected: <INSERT THE RESULT INSTEAD OF THE TEXT>
but got: True
^
Now, this could be my fault, because I needed to bump up base to 4.15, and doctest to 0.18 in order to get the cabal build
to run in docker/haskell.
Neither DoctestChapter3.hs
nor test/Test/Chapter3.hs
contain any tests.
Just a collection of some ideas to improve the course and make some tasks better. A few things I have on my mind and discussed with @vrom911:
lastDigit
that doesn't require thinking about corner cases.foo x y = show (x + y)
.Append
people don't need to create a separate List
newtype for lists.Hey Awesome people, First of all thank you very much for the amazing idea of learning Haskell in 4 PRs with Hacktoberfest (I
absolutely love the Idea β€οΈ )
I'm trying to define a function in Glassgow Haskell Compiler's REPL by executing the following line :
prelude> roundSubtract :: Double -> Int -> Int
and It results in the following error:
<interactive>:3:1: error:
β’ No instance for (Show (Double -> Int -> Int))
arising from a use of βprintβ
(maybe you haven't applied a function to enough arguments?)
β’ In a stmt of an interactive GHCi command: print it
On the tutorial, In Chapter1.hs
, on line 358, It asks to do it.
{- |
=βοΈ= Task 7
Write a function that takes elements of a list only in even positions.
π― HINT: You need to write a recursive function that pattern matches
on the list structure. Your function will have several cases and
probably needs to use nested pattern matching on lists of size at
least 2. Alternatively, you can use the "Recursive go" pattern.
>>> takeEven [2, 1, 3, 5, 4]
[2,3,4]
-}
Shouldn't it be dropEven
or takeOdd
?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.