Marco Perone
Programming language
elm make Main.elm
-- NICE TO MEET YOU ---------------------------------------
message = "hello everybody!"
main = text mesage
-- NAMING ERROR -------------------------------------------
Cannot find variable `mesage`
7| text mesage
^^^^^^
Maybe you want one of the following?
message
A sequence of program instructions that perform a specific task, packaged as a unit
function doSomething(arguments)
{
result = someOperationOn(arguments);
return result;
}
var specialIndex = 'key';
function setSpecialIndex(object, value) {
object[specialIndex] = value;
return object;
}
specialIndex = "key"
setSpecialIndex object index value =
{ object | index = value }
State can not be modified after it is created
message = "hello everybody!"
message = "hello again!"
-- DUPLICATE DEFINITION -----------------------------------
Naming multiple top-level values `message` makes things
ambiguous. When you say `message` which one do you want?
8| message = "hello again!"
^^^^^^^
Find all the top-level values named `message` and do some
renaming. Make sure the names are distinct!
The type of every expression is determined at compile type, before the application runs
addThree int = int + 3
addThree "4"
-- TYPE MISMATCH ------------------------------------------
The argument to function `addThree` is causing a mismatch.
8| addThree "4"
^^^
Function `addThree` is expecting the argument to be:
Int
But it is:
String
addThree : number -> number
addThree int = int + 3
addThree : Int -> Int
addThree int = int + 3
type alias Disk = Int
type alias Model = ( List Disk, List Disk, List Disk )
What if...
model = ([1, 3, 5], [1, 2], [])
type Position
= FirstPeg
| SecondPeg
| ThirdPeg
type alias Model = List Position
type alias Model =
{ status : Hanoi.Model
, from : Maybe Peg
, to : Maybe Peg
, message : Maybe String
}
view : Model -> Html Msg
view model =
div [ class "container" ]
[ div [ class "pegs" ]
[ div [ class "peg" ]
[ ol [ class "pegList" ]
( List.map viewDisk
fst ( disposition model.status )
)
]
, ...
viewDisk : Int -> Html Msg
viewDisk i =
li [ id ( "disk" ++ toString i ), class "disk" ] []
type Msg
= From ( Maybe Peg )
| To ( Maybe Peg )
| Error String
| Move Peg Peg
view : Model -> Html Msg
view model =
...
div [ class "hanoi-controls" ]
[ button
[ onClick ( tryMove model ) ]
[ text "Move" ]
]
tryMove : Model -> Msg
tryMove model =
case ( model.from, model.to ) of
( Nothing, _ ) -> Error "Starting peg missing"
( _, Nothing ) -> Error "Ending peg missing"
( Just from, Just to ) -> Move from to
update : Msg -> Model -> Model
update msg model =
case msg of
From maybePeg ->
{ model | from = maybePeg, message = Nothing }
To maybePeg ->
{ model | to = maybePeg, message = Nothing }
Error message ->
{ model | message = Just message }
Move from to ->
performMove model.status from to
type Msg
= From ( Maybe Peg )
| To ( Maybe Peg )
| Error String
| RequestMove Peg Peg
| Move Peg Peg
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
...
RequestMove from to ->
let
encodedJson =
encode 4
( object
[( "from", int ( toInt from ))
,( "to", int ( toInt to ))
]
)
in
( model, WS.send "ws://host" encodedJson )
subscriptions : Model -> Sub Msg
subscriptions : Model -> Sub Msg
subscriptions model =
WS.listen "ws://host" decodeMessage
decodeMessage : String -> Msg
Rate the talks!!! legacy.joind.in/19115