unison
unison copied to clipboard
No nice message for pattern match error
Version: release/0.5.36
Error:
grain/main>
Loading changes detected in ~/workspace-unison/scratch-dev/grain.u.
Sorry, you hit an error we didn't make a nice message for yet.
Here is a summary of the Note:
simple cause:
TypeMismatch
context:
Γ
|start1|
Grain.ref13 : Text -> GrainSpec m5 -> GrainRef m5
Grain.send16 : m15 -> GrainRef m15 ->{GrainContext} Unit
Grain.spec37 : s23 -> (Unit ->{Grain m20, Store s23, GrainContext} Unit) -> GrainSpec m20
GrainSpec.behavior95 : GrainSpec m41 -> Unit ->{Grain m41, Store s44, GrainContext} Unit
GrainSpec.initialState145 : GrainSpec m99 -> s102
|𝕩146|
|effect148|
effect147 : Unit ->{GrainContext} Unit
|𝕩149|
'User "\120150"-150
'User "v"-158
'User "k"-160
'𝕗159 = Map
'𝕗157 = Map k160
'a151 = Map k160 v158
'User "g"-152
'User "v"-153
'k154 = k160
'v155 = v158
'Inference Ability-156
|()162|
()161 : Unit
'Inference PatternPureV-172
'Inference Ability-175
'𝕖176 = GrainContext
'𝕦174 = 𝕖175, GrainContext
'𝕗173 = Request
'𝕗171 = Request {𝕖175, GrainContext}
'j4s9cq5p0k1164 = Request {𝕖175, GrainContext} 𝕧172
'Inference Ability-290
'User "m"-295
'𝕗294 = Grain
'𝕖291 = Grain m295
'Inference Ability-292
'Inference Ability-293
'𝕖165 = 𝕖290, Grain m295, 𝕖292, 𝕖293
'Inference Output-166
j4s9cq5p0k1163 : Request {𝕖175, GrainContext} 𝕧172
'User "m"-167
'𝕖169 = 𝕖175
'𝕧168 = 𝕧172
'Inference Ability-170
'User "v"-194
'User "m"-286
'm287 = m286
'm288 = m286
'f289 = _GrainSpec m286
Scratch file:
ability Grain m where
receive : m
ability GrainContext where
_send : m -> GrainRef m -> ()
type _GrainSpec m s = _GrainSpec s ('{Grain m, Store s, GrainContext} ())
type GrainSpec m = GrainSpec (Exists (_GrainSpec m))
GrainSpec.initialState : GrainSpec m -> s
GrainSpec.initialState = cases
GrainSpec impl ->
impl |> Exists.apply cases _GrainSpec s _ -> Any s |> unsafeExtract
GrainSpec.behavior : GrainSpec m -> ('{Grain m, Store s, GrainContext} ())
GrainSpec.behavior = cases
GrainSpec impl ->
impl |> Exists.apply cases _GrainSpec _ b -> Any b |> unsafeExtract
type GrainRef m = GrainRef Text (GrainSpec m)
Grain.send = GrainContext._send
Grain.spec : s -> ('{Grain m, Store s, GrainContext} ()) -> GrainSpec m
Grain.spec initialState behavior =
GrainSpec (Exists.wrap (_GrainSpec initialState behavior))
Grain.ref : Text -> GrainSpec m -> GrainRef m
Grain.ref id spec = GrainRef id spec
type PlayerMessage = ;
type Player = Player (GrainRef PlayerMessage)
Player.ref : Text -> Player
Player.ref name =
ref =
Grain.ref
name
(Grain.spec 0 do
match Grain.receive with
_ -> ()
()
)
Player ref
type RoomMessage = Join Player | GetPlayers ([Player] ->{GrainContext} ())
type Room = Room (GrainRef RoomMessage)
Room.ref : Text -> Room
Room.ref name =
ref =
Grain.ref
name
(Grain.spec [] do
match Grain.receive with
RoomMessage.Join player ->
Store.modify ((List.+:) player)
GetPlayers callback ->
callback Store.get
()
)
Room ref
Room.join : Player -> Room -> ()
Room.join player room =
(Room ref) = room
ref |> Grain.send (RoomMessage.Join player)
Room.getPlayers : ([Player] ->{GrainContext} ()) -> Room -> ()
Room.getPlayers callback room =
(Room ref) = room
ref |> Grain.send (GetPlayers callback)
main = do
Grain.run do
player1 = Player.ref "alvaro"
player2 = Player.ref "alex"
player3 = Player.ref "adam"
room = Room.ref "room1"
room |> join player1
room |> join player2
room |> join player3
room |> getPlayers (trace "players")
()
type GrainThread = GrainThread Text Any
Grain.run : '{GrainContext} () ->{} ()
Grain.run effect =
Store.withInitialValue Map.empty do
handle effect() with cases
{ GrainContext._send msg (GrainRef grainId spec) -> k } ->
grainOpt = Store.get |> Map.get grainId
match grainOpt with
None ->
initialState = GrainSpec.initialState spec
behavior = GrainSpec.behavior spec
Store.withInitialValue initialState do
behavior()
Debug.trace "initialState" initialState
Debug.trace "behavior" behavior
thread = GrainThread grainId
()
Some grain -> ()
trace "grainOpt" grainOpt
todo "context"
{ _ } ->
todo "end"
()