Coder Social home page Coder Social logo

kowainik / learn4haskell Goto Github PK

View Code? Open in Web Editor NEW
973.0 973.0 826.0 945 KB

πŸ‘©β€πŸ« πŸ‘¨β€πŸ« Learn Haskell basics in 4 pull requests

Home Page: https://kowainik.github.io/projects/learn4haskell

License: Mozilla Public License 2.0

Haskell 98.63% Makefile 1.37%
hacktoberfest hacktoberfest2020 hacktoberfest2021 haskell learning-by-doing

learn4haskell's People

Contributors

aelbozie avatar alexkassil avatar arpl-c-63h avatar arumugamtp avatar burenkov-anton avatar chshersh avatar d-l-n avatar dariodsa avatar dependabot[bot] avatar graceful-potato avatar hasrthur avatar imba-tjd avatar isthatcentered avatar iwanttokeepanon avatar krivtsov avatar marcellourbani avatar mediumdoggo avatar mjcz-archived avatar pennychase avatar pro2s avatar recluse27 avatar ridoca avatar staff0rd avatar sylk avatar thanakritju avatar thth avatar vrom911 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

learn4haskell's Issues

Is this wording about typeclasses correct in Chapter3.hs?

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)?

SPELLING ERROR

IN THE README THERE IS A SPELLING ERROR #98
CHANGED "ETA REDUCTION" TO "BETA REDUCTION"

Useful to have docker instructions in README.md?

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?

Build dependency happy fails on OSX 10.15.7

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

Bug in est/Test/Chapter1.hs ?

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

Unable to open pull request for Chapter 4

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

README.md: *boiling

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 ;)

Odd test output results

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.

Save @vrom911's and @chshersh's time by including solutions

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.

Chapter2: takeEven or dropEven?

{- |
=βš”οΈ= 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?

[error] Function Definition in GHCi on Linux 5.8

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.

CC: @chshersh @vrom911

Question about a test

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 ?

Chapter 3 knight Monster clarification

@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.

Error resolving dependencies while make test-chapter1-basic.

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

Main project description

  • What is it
  • Goals
  • Is it suitable for you?
  • How to participate
  • How to open PRs and ask our review
  • ???

Ideas for new tasks/changes to the existing tasks

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:

  • Chapter 1: A simpler task before lastDigit that doesn't require thinking about corner cases.
  • Chapter 2: Maybe eta-reduction task where you shouldn't eta-reduce?
  • Chapter 3: A task on typeclasses to write the type of a function like foo x y = show (x + y).
  • Chapter 3: Make sure that the first fight is only one round, no recursion.
  • Chapter 3: Clarify, that in Append people don't need to create a separate List newtype for lists.
  • Chapter 4: The advanced task can make use of Monads to practice this topic more.

Property testing

  • Typeclass laws
  • duplicate: length (duplicate xs) = 2 * (lenght xs)
  • rewind = reverse

doctest failed

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...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.