Hello, first time elm user here.
I am trying to create a program that encodes some parking spot data as json and sends it through a port.
The example in the docs mention cache (E.int 42)
where cache
is the name of the port.
I tried to modify this slightly, my port is named spotter
, but when i compile i get the following error:
Something went wrong while parsing spotter's definition.
46| spotter jason
47|
48| main =
^
I was expecting to see the rest of spotter's definition. Maybe you forgot some
code? Or maybe the body of `spotter` needs to be indented?
Program is here:
port module Main exposing (..)
import Json.Encode as E
import Html as H
import Browser
-- PORTS
port spotter : E.Value -> Cmd msg
-- PARKING INFO
type alias State =
{ string : String
, bool : Bool
}
type alias Spot =
{ id : Int
, longitude : Float
, latitude : Float
, available : State
}
-- ENCODERS
encodeSpot : Spot -> E.Value
encodeSpot spot =
E.object
[ ("id", E.int spot.id)
, ("longitude", E.float spot.longitude)
, ("latitude", E.float spot.latitude)
, ("available", encodeState spot.available)
]
encodeState : State -> E.Value
encodeState state =
E.object
[ ("string", E.string state.string)
, ("bool", E.bool state.bool)
]
testState = State "free" True
testSpot = Spot 55 3.3 3.3 testState
jason = encodeSpot testSpot
-- send through port
spotter jason
-- placeholder main
main =
H.text testSpot.available.string
What is wrong?