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

Commit fd8edba

Browse files
author
Abigail Magalhães
committedApr 27, 2020
Pretty types properly in the type overlay
1 parent d425fa6 commit fd8edba

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed
 

‎.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/dist
22
/dist-newstyle
33
/result
4+
.vscode/
45
*.lua
56
*.ss
67
/*.out
@@ -47,3 +48,5 @@ doc/*.synctex.gz
4748

4849
/.idea
4950
*.iml
51+
52+
*.tix

‎amuletml.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ library
249249
, time >= 1.9.3 && < 1.9.4
250250
, these >= 1 && < 1.1
251251
, array >= 0.5 && < 0.6
252+
, logict >= 0.7 && < 0.8
252253
, filepath >= 1.4 && < 1.5
253254
, hashable >= 1.2 && < 1.4
254255
, directory >= 1.3 && < 1.4
@@ -261,7 +262,6 @@ library
261262
, cryptohash-sha256 >= 0.11 && < 0.12
262263
, annotated-wl-pprint >= 0.7 && < 0.8
263264
, unordered-containers >= 0.2 && < 0.3
264-
, logict >= 0.7 && < 0.8
265265
, pretty-show
266266

267267
hs-source-dirs: src

‎bin/AmuletLsp/Features/TypeOverlay.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@ resolveTypeOverlay env (OverlayData v n _) (CodeLens range Nothing _) =
7070
in case env ^. names . at var of
7171
Nothing -> Nothing
7272
Just ty ->
73-
let cmd = Command (renderBasic $ pretty var <+> colon <+> displayType ty) "" Nothing
73+
let cmd = Command (renderBasic $ pretty var <+> colon <+> displayTypeTyped ty) "" Nothing
7474
in Just (CodeLens range (Just cmd) Nothing)
7575
resolveTypeOverlay _ _ c@(CodeLens _ Just{} _) = Just c

‎src/Syntax/Pretty.hs

+22-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{-# LANGUAGE FlexibleContexts, UndecidableInstances
2-
, FlexibleInstances, OverloadedStrings, ScopedTypeVariables, GADTs #-}
2+
, FlexibleInstances, OverloadedStrings, ScopedTypeVariables, GADTs, ViewPatterns #-}
33
module Syntax.Pretty (displayType, applyCons, prettyMotive, displayTypeTyped) where
44

55
import Control.Lens hiding (Lazy)
@@ -114,9 +114,13 @@ prettyType (TyApp (TyCon v _) x) | show (pretty v) == mempty = displayType x
114114
-- This is really gross
115115

116116
prettyType (TyApp x e) = parenTyFun x (displayType x) <+> parenTyArg e (displayType e)
117-
prettyType (TyRows p rows) = enclose (lbrace <> space) (space <> rbrace) $
117+
118+
prettyType (flatRows -> Just (Just p, rows)) = enclose (lbrace <> space) (space <> rbrace) $
118119
pretty p <+> soperator pipe <+> hsep (punctuate comma (displayRows rows))
119-
prettyType (TyExactRows rows) = record (displayRows rows)
120+
prettyType (flatRows -> Just (Nothing, rows)) = record (displayRows rows)
121+
prettyType TyRows{} = error "unmatched flatRows"
122+
prettyType TyExactRows{} = error "unmatched flatRows"
123+
120124
prettyType (TyTupleL x y) = parens $ prettyType x <> comma <+> prettyType y
121125
prettyType (TyTuple t s) =
122126
parenTyFun t (displayType t) <+> soperator (char '*') <+> parenTuple s (displayType s)
@@ -134,7 +138,7 @@ prettyTypeTyped t@TyWithConstraints{} = displayTypeTyped (applyCons t)
134138
prettyTypeTyped x@TyPromotedCon{} = pretty x
135139

136140
prettyTypeTyped (TyWildcard x) = case x of
137-
Just ty -> displayType ty
141+
Just ty -> displayTypeTyped ty
138142
Nothing -> skeyword (char '_')
139143
prettyTypeTyped (TySkol v) = stypeSkol (squote <> pretty (v ^. skolVar))
140144
prettyTypeTyped (TyPi x t) = uncurry (prettyQuantifiers prettyTypeTyped) . second reverse $ unwind t [x] where
@@ -149,16 +153,26 @@ prettyTypeTyped (TyApp (TyCon v _) x) | show (pretty v) == mempty = displayTypeT
149153
prettyTypeTyped (TyApp x e) = parenTyFun x (displayType x) <+> parenTyArg' e (displayTypeTyped e) where
150154
parenTyArg' e d | Just _ <- listType e = d
151155
parenTyArg' e d = parenTyArg e d
152-
prettyTypeTyped (TyRows p rows) = enclose (lbrace <> space) (space <> rbrace) $
153-
pretty p <+> soperator pipe <+> hsep (punctuate comma (displayRows rows))
154-
prettyTypeTyped (TyExactRows rows) = record (displayRowsTyped rows)
155156
prettyTypeTyped (TyTupleL x y) = parens $ prettyTypeTyped x <> comma <+> prettyTypeTyped y
156157
prettyTypeTyped (TyTuple t s) =
157-
parenTyFun t (displayType t) <+> soperator (char '*') <+> parenTuple s (displayType s)
158+
parenTyFun t (displayTypeTyped t) <+> soperator (char '*') <+> parenTuple s (displayTypeTyped s)
158159
prettyTypeTyped (TyParens t) = parens $ prettyTypeTyped t
159160
prettyTypeTyped (TyOperator l o r) = prettyTypeTyped l <+> pretty o <+> prettyTypeTyped r
160161
prettyTypeTyped TyType = keyword "type"
161162
prettyTypeTyped (TyLit l) = pretty l
163+
prettyTypeTyped (flatRows -> Just (Just p, rows)) = enclose (lbrace <> space) (space <> rbrace) $
164+
pretty p <+> soperator pipe <+> hsep (punctuate comma (displayRows rows))
165+
prettyTypeTyped (flatRows -> Just (Nothing, rows)) = record (displayRowsTyped rows)
166+
prettyTypeTyped TyRows{} = error "unmatched flatRows"
167+
prettyTypeTyped TyExactRows{} = error "unmatched flatRows"
168+
169+
flatRows :: Type p -> Maybe (Maybe (Type p), [(Text, Type p)])
170+
flatRows (TyExactRows rs) = Just (Nothing, rs)
171+
flatRows (TyRows t rs) =
172+
case flatRows t of
173+
Nothing -> Just (Just t, rs)
174+
Just (t', rs') -> Just (t', rs ++ rs')
175+
flatRows _ = Nothing
162176

163177
displayRows :: (Ord (Var p), Pretty (Var p)) => [(Text, Type p)] -> [Doc]
164178
displayRows = map (\(n, v) -> text n <+> colon <+> displayType v) . sortOn fst

0 commit comments

Comments
 (0)
This repository has been archived.