From ae8734d11736db91bb2e4be070ca6a8b27347213 Mon Sep 17 00:00:00 2001 From: Paul Chiusano Date: Wed, 18 Feb 2015 18:35:30 -0500 Subject: [PATCH] Round trip working with new framework --- editor/src/Elmz/Json/Request.elm | 1 + editor/src/Unison/Editor.elm | 66 ++++++++++++++++---------------- editor/src/Unison/Type.elm | 10 ++--- 3 files changed, 40 insertions(+), 37 deletions(-) diff --git a/editor/src/Elmz/Json/Request.elm b/editor/src/Elmz/Json/Request.elm index 707dde7cb..c90b7bb36 100644 --- a/editor/src/Elmz/Json/Request.elm +++ b/editor/src/Elmz/Json/Request.elm @@ -58,5 +58,6 @@ decodeResponse : Decoder a -> Http.Response String -> Result (Status String) a decodeResponse p r = case r of Http.Success body -> case Decoder.decodeString p body of Result.Err e -> Result.Err (Failed e) + Result.Ok a -> Result.Ok a Http.Waiting -> Result.Err Waiting Http.Failure code body -> Result.Err <| Failed ("error " ++ toString code ++ "\n" ++ body) diff --git a/editor/src/Unison/Editor.elm b/editor/src/Unison/Editor.elm index 65e062524..77c7534fb 100644 --- a/editor/src/Unison/Editor.elm +++ b/editor/src/Unison/Editor.elm @@ -404,7 +404,8 @@ withStatus r = case r of Result.Err status -> \model -> let f s = case status of JR.Inactive -> List.drop 1 s - _ -> status :: s + JR.Waiting -> status :: s + JR.Failed e -> let l = Debug.log e () in status :: s in norequest { model | status <- f model.status } Result.Ok action -> action @@ -413,34 +414,35 @@ search2 searchbox origin reqs = let openEdit r = case r of Open term path -> Just (term,path) _ -> Nothing - --openEdit' = - -- let go oe model = norequest (refreshExplorer searchbox { model | localInfo <- Just oe }) - -- in Signal.map openEdit reqs - -- |> JR.send (Node.localInfo host `JR.to` go) (model0.term, []) - -- |> Signal.map withStatus - --search r = case r of - -- Search typ query -> Just (typ,query) - -- _ -> Nothing - --declare r = case r of - -- Declare term -> Just term - -- _ -> Nothing - --edit r = case r of - -- -- todo: reroot the request to point to tightest bound term - -- Edit rootPath relPath action term -> Just (rootPath,relPath,action,term) - -- _ -> Nothing - --edit' = - -- let go (path,old,new) model = case Term.at path model.term of - -- Nothing -> norequest model - -- Just old' -> - -- if old == old' - -- then case Term.set path model.term new of - -- Just term -> let m2 = { model | term <- term } - -- in norequest (refreshPanel (Just searchbox) origin m2) - -- Nothing -> norequest model - -- else norequest model - -- in Signal.map edit reqs - -- |> JR.send (Node.editTerm host `JR.to` go) ([],[],Action.Noop,model0.term) - -- |> Signal.map withStatus + openEdit' = + let go oe model = + norequest (refreshExplorer searchbox { model | localInfo <- Just (Debug.log "info" oe) }) + in Signal.map openEdit reqs + |> JR.send (Node.localInfo host `JR.to` go) (model0.term, []) + |> Signal.map withStatus + search r = case r of + Search typ query -> Just (typ,query) + _ -> Nothing + declare r = case r of + Declare term -> Just term + _ -> Nothing + edit r = case r of + -- todo: reroot the request to point to tightest bound term + Edit rootPath relPath action term -> Just (rootPath,relPath,action,term) + _ -> Nothing + edit' = + let go (path,old,new) model = case Term.at path model.term of + Nothing -> norequest model + Just old' -> + if old == old' + then case Term.set path model.term new of + Just term -> let m2 = { model | term <- term } + in norequest (refreshPanel (Just searchbox) origin m2) + Nothing -> norequest model + else norequest model + in Signal.map edit reqs + |> JR.send (Node.editTerm host `JR.to` go) ([],[],Action.Noop,model0.term) + |> Signal.map withStatus metadatas r = case r of Metadatas rs -> Just rs _ -> Nothing @@ -453,7 +455,7 @@ search2 searchbox origin reqs = |> JR.send (Node.metadatas host `JR.to` go) [] |> Signal.map withStatus noop model = norequest model - in Signal.constant noop-- openEdit' `Signal.merge` metadatas' `Signal.merge` edit' + in openEdit' `Signal.merge` metadatas' `Signal.merge` edit' main = let origin = (15,15) @@ -474,7 +476,7 @@ main = (search2 (Signal.send inputs.searchbox) origin) { model0 | term <- Terms.int 42 } debug model = - let summary model = model.explorer - in Debug.watchSummary "model" summary model + model |> Debug.watchSummary "explorer" .explorer + |> Debug.watchSummary "status" .status ms' = Signal.map debug ms in Signal.map view ms' diff --git a/editor/src/Unison/Type.elm b/editor/src/Unison/Type.elm index cc4c471d0..272a3e8f8 100644 --- a/editor/src/Unison/Type.elm +++ b/editor/src/Unison/Type.elm @@ -31,7 +31,7 @@ type Kind = Star | KArrow Kind Kind decodeKind : Decoder Kind decodeKind = Decoder.union' <| \t -> if | t == "Star" -> Decoder.unit Star - | t == "Arrow" -> Decoder.map2 KArrow decodeKind decodeKind + | t == "Arrow" -> Decoder.product2 KArrow decodeKind decodeKind decodeLiteral : Decoder Literal decodeLiteral = Decoder.union' <| \t -> @@ -43,12 +43,12 @@ decodeLiteral = Decoder.union' <| \t -> decodeType : Decoder Type decodeType = Decoder.union' <| \t -> if | t == "Unit" -> Decoder.map Unit decodeLiteral - | t == "Arrow" -> Decoder.map2 Arrow decodeType decodeType + | t == "Arrow" -> Decoder.product2 Arrow decodeType decodeType | t == "Universal" -> Decoder.map Universal V.decode | t == "Existential" -> Decoder.map Existential V.decode - | t == "Kind" -> Decoder.map2 Ann decodeType decodeKind - | t == "Constrain" -> Decoder.map2 Constrain decodeType (Decoder.unit ()) - | t == "Forall" -> Decoder.map2 Forall V.decode decodeType + | t == "Kind" -> Decoder.product2 Ann decodeType decodeKind + | t == "Constrain" -> Decoder.product2 Constrain decodeType (Decoder.unit ()) + | t == "Forall" -> Decoder.product2 Forall V.decode decodeType encodeKind : Encoder Kind encodeKind k = case k of