
Bug by Nestor Ferraro / CC BY 2.0
Once it compiles, it just works!
import Html
main = Html.text "Hello Bochum!"
import Html
greet str = Html.text str
main =
greet "Hello Bochum!"
import Html exposing (Html)
greet : String -> Html a
greet str =
Html.text str
main : Html a
main =
greet "Hello Bochum!"
type alias Model = Int
model : Model
model = 0
type Msg = Increment | Decrement
view : Model -> Html Msg
view model =
div []
[ div [] [ text (toString model) ]
, button [ onClick Decrement ] [ text "-" ]
, button [ onClick Increment ] [ text "+" ]
]
update : Msg -> Model -> Model
update msg model =
case msg of
Increment -> model + 1
Decrement -> model - 1
view: Model -> Html Msgupdate: Msg -> Model -> ModelThat's all there is.
(nearly)
Cmd)Sub)view: Model -> Html Msgupdate: Msg -> Model -> (Model, Cmd Msg)...and the type system, too
myFunction str =
String.repeat 3 str
main =
Html.text (myFunctino "Elm")
-- NAMING ERROR ----------------------- errors/Spelling.elm
Cannot find variable `myFunctino`
9│ Html.text (myFunctino "Elm")
^^^^^^^^^^
Maybe you want one of the following?
myFunction
subMismatch =
{ name = "Alice", age = 24 } == { name = "Bob", age = "30" }
-- TYPE MISMATCH --------------------- errors/SubMismatch.elm
The right argument of (==) is causing a type mismatch.
2│ { name = "Alice", age = 24 } == { name = "Bob", age = "30" }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(==) is expecting the right argument to be a:
{ ..., age : number }
But the right argument is:
{ ..., age : String }
type Colour = Red | Green | Blue
colourToHex : Colour -> String
colourToHex colour =
case colour of
Red -> "#f00"
Green -> "#0f0"
-- MISSING PATTERNS --------------- errors/ForgottenCase.elm
This `case` does not have branches for all possibilities.
5│> case colour of
6│> Red -> "#f00"
7│> Green -> "#0f0"
You need to account for the following values:
Blue
Add a branch to cover this pattern!
function repeatFirst(list) {
var repeated = list[0].repeat(3);
alert(repeated);
}
var list1 =
[ 'hip', 'hop', 'hooray!' ];
...
repeatFirst(list1);
var list2 = [];
...
repeatFirst(list2);
repeatFirst list =
let elem = List.head list
in String.repeat 3 elem
> elm-make RepeatFirst.elm --output repeat-first.html
-- TYPE MISMATCH -------------------------- RepeatFirst.elm
The 2nd argument to function repeat is causing a mismatch.
8│ String.repeat 3 elem
^^^^
Function `repeat` is expecting the 2nd argument to be:
String
But it is:
Maybe a
Hint: I always figure out the type of arguments from left
to right. If an argument is acceptable when I check it, I
assume it is "correct" in subsequent checks. So the problem
may actually be in how previous arguments interact with the
2nd.
repeatFirst list =
let
maybeElem = List.head list
elem = Maybe.withDefault "" maybeElem
in
String.repeat 3 elem
> elm-make RepeatFirst.elm --output repeat-first.html
Success! Compiled 1 modules.
Successfully generated repeat-first.html
... and it's changing the frontend game right now
