Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

some work on improving tuple type printing #42

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client-src/Ucb/Main/View.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down
54 changes: 34 additions & 20 deletions client-src/Ucb/Main/View/Type.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions client-src/Unison/Reference.elm
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ module Unison.Reference exposing
, idEquality
, idHashing
, idToString
, pairReference
, referenceEquality
, referenceHashing
, unitReference
)

import Misc exposing (tumble)
Expand Down Expand Up @@ -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
}
49 changes: 49 additions & 0 deletions client-src/Unison/Type.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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