From 2605ead9095e3812cedd539af8a7a9b7f195675c Mon Sep 17 00:00:00 2001 From: Mitchell Rosen Date: Tue, 10 Sep 2019 19:55:49 -0400 Subject: [PATCH] some work on improving tuple type printing --- client-src/Ucb/Main/View.elm | 2 +- client-src/Ucb/Main/View/Type.elm | 54 +++++++++++++++++++------------ client-src/Unison/Reference.elm | 20 ++++++++++++ client-src/Unison/Type.elm | 49 ++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 21 deletions(-) diff --git a/client-src/Ucb/Main/View.elm b/client-src/Ucb/Main/View.elm index d3015e4..45f0dc9 100644 --- a/client-src/Ucb/Main/View.elm +++ b/client-src/Ucb/Main/View.elm @@ -213,7 +213,7 @@ viewBranches view = ) -- Should we show this branch? - -- Yes if: + -- Yes if, after applying the search filter, -- * It contains any types -- * It contains any non-constructor terms shouldBeVisible : diff --git a/client-src/Ucb/Main/View/Type.elm b/client-src/Ucb/Main/View/Type.elm index 148e9e3..e11455d 100644 --- a/client-src/Ucb/Main/View/Type.elm +++ b/client-src/Ucb/Main/View/Type.elm @@ -42,26 +42,40 @@ viewType view p ty0 = ) TypeTm (TypeApp ty1 ty2) -> - case ty1.out of - TypeTm (TypeRef (Builtin "Sequence")) -> - row - [] - [ text "[", viewType view 0 ty2, text "]" ] - - _ -> - case typeUnApps ty0 of - Nothing -> - impossible "viewType: unApps returned Nothing" - - Just ( f, xs ) -> - ppParen (p >= 10) - (row - [] - [ viewType view 9 f - , text " " - , ppSpaced (List.map (viewType view 10) xs) - ] - ) + if typeIsSequenceRef ty1 then + row + [] + [ text "[", viewType view 0 ty2, text "]" ] + + else if typeIsPairRef ty1 then + let + tys : List (Type Symbol) + tys = + typeUnTuple ty2 + in + -- Print a horrible looking monster because Ian is + -- working on a better type printer. + row + [] + [ text "(TUPLE " + , row [] (List.map (viewType view 10) tys) + , text ")" + ] + + else + case typeUnApps ty0 of + Nothing -> + impossible "viewType: unApps returned Nothing" + + Just ( f, xs ) -> + ppParen (p >= 10) + (row + [] + [ viewType view 9 f + , text " " + , ppSpaced (List.map (viewType view 10) xs) + ] + ) TypeTm (TypeForall _) -> let diff --git a/client-src/Unison/Reference.elm b/client-src/Unison/Reference.elm index dd5287f..bbd30b1 100644 --- a/client-src/Unison/Reference.elm +++ b/client-src/Unison/Reference.elm @@ -4,8 +4,10 @@ module Unison.Reference exposing , idEquality , idHashing , idToString + , pairReference , referenceEquality , referenceHashing + , unitReference ) import Misc exposing (tumble) @@ -92,3 +94,21 @@ idToString { hash, pos, size } = ++ String.fromInt pos ++ String.fromChar 'c' ++ String.fromInt size + + +pairReference : Reference +pairReference = + Derived + { hash = "onbcm0qctbnuctpm57tkc5p16b8gfke8thjf19p4r4laokji0b606rd0frnhj103qb90lve3fohkoc1eda70491hot656s1m6kk3cn0" + , pos = 0 + , size = 1 + } + + +unitReference : Reference +unitReference = + Derived + { hash = "568rsi7o3ghq8mmbea2sf8msdk20ohasob5s2rvjtqg2lr0vs39l1hm98urrjemsr3vo3fa52pibqu0maluq7g8sfg3h5f5re6vitj8" + , pos = 0 + , size = 1 + } diff --git a/client-src/Unison/Type.elm b/client-src/Unison/Type.elm index 06a01fe..45df89b 100644 --- a/client-src/Unison/Type.elm +++ b/client-src/Unison/Type.elm @@ -225,3 +225,52 @@ typeUnForalls vars ty = _ -> ( List.reverse vars, ty ) + + +typeUnTuple : + Type var + -> List (Type var) +typeUnTuple ty = + case ty.out of + TypeTm (TypeRef ref) -> + if ref == unitReference then + [] + + else + impossible "typeUnTuple: didn't end with ()?" + + _ -> + case typeUnApps ty of + Just ( f, [ ty1, ty2 ] ) -> + case f.out of + TypeTm (TypeRef ref) -> + if ref == pairReference then + ty1 :: typeUnTuple ty2 + + else + impossible "typeUnTuple: not pair?" + + _ -> + impossible "typeUnTuple: not pair?" + + _ -> + impossible "typeUnTuple: wat?" + + +typeIsPairRef : + Type var + -> Bool +typeIsPairRef ty = + ty.out == TypeTm (TypeRef pairReference) + + +typeIsSequenceRef : + Type var + -> Bool +typeIsSequenceRef ty = + case ty.out of + TypeTm (TypeRef (Builtin "Sequence")) -> + True + + _ -> + False