bit of cleanup of Type prettyerinter

This commit is contained in:
Paul Chiusano 2015-08-10 13:52:20 -04:00
parent 6e1618d2dd
commit beccbd1302
2 changed files with 17 additions and 15 deletions

View File

@ -9,6 +9,7 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE OverloadedStrings #-}
module Unison.Doc where
@ -17,6 +18,7 @@ import Control.Comonad (extract)
import Control.Monad.State.Strict
import Data.Functor
import Data.List (intersperse)
import Data.String (IsString)
import Unison.Path (Path)
import qualified Unison.Path as Path
@ -330,3 +332,8 @@ sep delim ds = group (foldr1 combine ds)
sep' :: Path p => e -> [e] -> Doc e p
sep' delim ds = sep delim (map embed ds)
parenthesize :: (IsString s, Path p) => Bool -> Doc s p -> Doc s p
parenthesize b d =
let r = root d
in if b then docs [embed' r "(", d, embed' r ")"] else d

View File

@ -200,12 +200,6 @@ view :: (Reference -> Symbol View.DFO) -> ViewableType -> Doc Text Path
view ref t = go no View.low t
where
no = const False
(<>) = D.append
paren b d =
let r = D.root d
in if b then D.embed' r "(" <> d <> D.embed' r ")" else d
arr = D.breakable " " <> D.embed ""
sp = D.breakable " "
sym v = D.embed (Var.name v)
op :: ViewableType -> Symbol View.DFO
op t = case t of
@ -217,8 +211,9 @@ view ref t = go no View.low t
go :: (ViewableType -> Bool) -> View.Precedence -> ViewableType -> Doc Text Path
go inChain p t = case t of
ArrowsP' spine ->
paren (p > View.low) . D.group . D.delimit arr $
[ D.sub' p (go no (View.increase View.low) s) | (s,p) <- spine ]
let arr = D.breakable " " `D.append` D.embed ""
in D.parenthesize (p > View.low) . D.group . D.delimit arr $
[ D.sub' p (go no (View.increase View.low) s) | (s,p) <- spine ]
AppsP' (fn,fnP) args ->
let
Symbol _ name view = op fn
@ -229,16 +224,16 @@ view ref t = go no View.low t
in
(if inChain fn then id else D.group) $ case remaining of
[] -> applied
args -> paren (p > View.high) . D.group . D.docs $
[ applied, sp
, D.nest " " . D.group . D.delimit sp $
args -> D.parenthesize (p > View.high) . D.group . D.docs $
[ applied, D.breakable " "
, D.nest " " . D.group . D.delimit (D.breakable " ") $
[ D.sub' p (go no (View.increase View.high) s) | (s,p) <- args ] ]
ForallsP' vs (body,bodyp) ->
if p == View.low then D.sub' bodyp (go no p body)
else paren True . D.group $
D.embed "" <>
D.delimit (D.embed " ") (map (sym . fst) vs) <>
D.docs [D.embed ".", sp, D.nest " " $ D.sub' bodyp (go no View.low body)]
else D.parenthesize True . D.group $
D.embed "" `D.append`
D.delimit (D.embed " ") (map (sym . fst) vs) `D.append`
D.docs [D.embed ".", D.breakable " ", D.nest " " $ D.sub' bodyp (go no View.low body)]
Constrain' t _ -> go inChain p t
Ann' t _ -> go inChain p t -- ignoring kind annotations for now
Universal' v -> sym v