-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Human-friendly metavariable printing #54
base: main
Are you sure you want to change the base?
Conversation
Naming. I reckon the current Then, the names here that we show to the user can be UserName...? Failing that, hmmm, VarName? It's not good as many of our names can stand for variables. UserVarName is too long and directs me back down the QualName route. SourceCodeName, also too long - and we can't abbreviate to SrcName because we have Src's everywhere. EDIT: VisName (yes short for visible), SurfaceName? |
e0963ab
to
303025f
Compare
303025f
to
42e299d
Compare
42e299d
to
4e06428
Compare
ensureEmpty str xs = err $ InternalError $ "Expected empty " ++ str ++ ", got:\n " ++ showSig (rowToSig xs) | ||
ensureEmpty str xs = do | ||
nm <- req AskNames | ||
err $ InternalError $ "Expected empty " ++ str ++ ", got:\n " ++ showRow nm xs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess there is no easy equivalent of format!
that we can partially apply to give a function from (string to insert into the middle) -> (another string with that inserted) ?
@@ -85,7 +85,7 @@ instance Show (Term d k) where | |||
show (VHole (name, _)) = '?' : name | |||
show Empty = "()" | |||
show (a :|: b) = bracket PJuxtPull a ++ ", " ++ bracket PJuxtPull b | |||
show Pass = "pass" | |||
show Pass = ".." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a drive-by fix - the surface syntax for the Pass
operator is ..
, not pass
@@ -216,3 +218,9 @@ data Precedence | |||
| PAnn | |||
| PApp | |||
deriving (Bounded, Enum, Eq, Ord, Show) | |||
|
|||
showSig :: (ty -> String) -> [(String, ty)] -> String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not much point in moving this...but where's showRow
gone? EDIT: in Syntax/Value.hs
where | ||
arrow = case modey :: Modey m of | ||
Braty -> "->" | ||
Kerny -> "-o" | ||
|
||
instance MODEY m => Show (CTy m n) where | ||
show = showWithMetas M.empty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds like we'll end up showing CTy's without user-names by accident....do we really need it?
where | ||
helper :: MODEY m => Some (Ro m n) -> String | ||
helper (Some ro) = show ro | ||
instance MODEY m => Show (Ro m bot top) where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similarly
show (NumValue 0 g) = show g | ||
show (NumValue n Constant0) = show n | ||
show (NumValue n g) = show n ++ " + " ++ show g | ||
instance ShowWithMetas x => ShowWithMetas (NumVal x) where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, how about fmap
-ing showWithMetas
over the variable to give a NumVal String
(or NumVal
of something that can be Show
n)
@@ -602,3 +660,13 @@ stkLen (zx :<< _) = Sy (stkLen zx) | |||
numValIsConstant :: NumVal (VVar Z) -> Maybe Integer | |||
numValIsConstant (NumValue up Constant0) = pure up | |||
numValIsConstant _ = Nothing | |||
|
|||
showRow :: ShowWithMetas ty => M.Map End String -> [(NamedPort e, ty)] -> String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, this now looks a bit like
instance ShowWithMetas ty => ShowWithMetas [(NamedPort e, ty)]
Although just using showWithMetas
when we used to use showRow
might be quite a jump...
@@ -164,6 +174,8 @@ deriving instance Eq io => Eq (CType' io) | |||
instance Semigroup (CType' (PortName, ty)) where | |||
(ss :-> ts) <> (us :-> vs) = (ss <> us) :-> (ts <> vs) | |||
|
|||
type UserNameMap = M.Map End String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about calling this NamesForMetas
or NamesForEnds
? (Is "Metas" a new term in this PR and if so do we want to suddenly introduce it like so, or is it a term we've been using in the code previously?
Closes #3.
There are a couple of open questions here:
nameMap
? I kind of likemnemonics
as we use for the user-provided names of holesreq AskNames >>= \nm -> showRow nm
pattern?I have a hunch this could look nicer after we tackle #23.
New test case
vec_length2.brat
reveals an error, which I plan to fix in #38.(This bit of code is driving me up the wall 😅)