Skip to content

llaisdy/elm7more

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

README

Overview

I thought the Elm chapter in “Seven More Languages in Seven Weeks” was very good. However, the Elm language has changed significantly since the chapter was published, so very few of the code examples worked as printed.

This repo contains all code examples from the chapter, updated for Elm 0.15 — and tested to be working.

Thank you very much to members of the Elm mailing list for help with count (day 2) and range (day 3).

The src/ directory contains updated version of code in the book’s source tarball. The other two scripts contain examples from day 2 from the book which were not included in the tarball.

The original code is available from the book’s web page:

https://pragprog.com/book/7lang/seven-more-languages-in-seven-weeks

I have read some of the other chapters in the book and I think they are as good as the Elm chapter. Each chapter gives a good flavour of the language it covers (the book covers Lua, Factor, Elm, Elixir, Julia, miniKanren, and Idris).

Day 1

The first day is all in the Elm REPL. There are two differences to note:

(p. 91) Error messages slightly different

Error messages have changed slightly. The book suggests that the REPL used to show “Expected” and “Actual” types, as in:

> 4 + "4"
[1 of 1] Compiling Repl
...

    Expected Type: number
      Actual Type: String

Error messages do report the type mismatch:

> 4 + "4"
## ERRORS in repl-temp-000.elm #################################################

-- TYPE MISMATCH --------------------------------------------- repl-temp-000.elm

The right argument of (+) is causing a type mismatch.

3|   4 + "4"
         ^^^
As I infer the type of values flowing through your program, I see a conflict
between these two types:

    number

    String

However, (in my experience so far) the order of the reported types is not always Expected, Actual. Sometimes it is Actual, Expected.

(p. 93) data -> type

The data keyword for declaring a new type is now type, as in:

type Color = Black | White

(p. 93) case is whitespace sensitive

When entering the case pattern matching example into a REPL, please be aware that each pattern must be prefixed by whitespace. The text provides this example:

> color = case piece of \
|   CP White _ -> White \
|   CP Black _ -> Black

Otherwise, there will be a parse error indicating,

I ran into something unexpected when parsing your code!

I am looking for one of the following things:

    end of input
    whitespace

(p. 95) map, filter, and foldl must be qualified with List module.

The REPL requires the `map` and `filter` functions to be qualified. These functions are used in several examples starting on page 95. The first example under the Working with Functions section should read:

> List.map anonymousInc [1, 2, 3]

(p. 99) Example DOES work in REPL

The text says that this example would not work in the REPL, but it does now.

xDist {x} = abs x

Day 2

As well as day2.elm and p106.echo.elm, all the scripts in src/ are for day2, apart from languageHeads.elm.

I have added necessary imports and made some lexical changes (e.g., lift is now Signal.map). I have also added some type annotations. Two other changes for day 2 code:

  • count (p. 103) no longer exists. Thanks to a member on the elm-discuss mailing list, day2.elm uses a foldp for this.
  • The echo example uses a Mailbox for message passing.

Day 3

I have updated languageHeads.elm for Elm 0.15. I have also corrected errors in the code: for example, the Head type was declared without an img field.

As well as languageHeads.elm, the book’s source tarball has game.elm, skeleton.elm, gameTwo.elm, and inputModel.elm.

range (in the input signal) no longer exists. Thanks to a member on the elm-discuss mailing list for providing a function for this.

About

Code for the Elm chapter in "Seven More Languages in Seven Weeks"

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages