Skip to content
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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

croyzor
Copy link
Collaborator

@croyzor croyzor commented Nov 11, 2024

Closes #3.

There are a couple of open questions here:

  1. What's a better name than nameMap? I kind of like mnemonics as we use for the user-provided names of holes
  2. What's your favourite factoring of the repeated req 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 😅)

@croyzor croyzor requested a review from acl-cqc November 11, 2024 19:04
@acl-cqc
Copy link
Collaborator

acl-cqc commented Nov 14, 2024

Naming. I reckon the current UserName should be QualName. Might as well be a newtype, rather than data, too, with the constructor also called QualName.

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?

@croyzor croyzor changed the base branch from main to refactor/qualname November 19, 2024 11:49
@croyzor croyzor self-assigned this Nov 20, 2024
Base automatically changed from refactor/qualname to main November 25, 2024 17:09
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
Copy link
Collaborator

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 = ".."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??

Copy link
Collaborator Author

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
Copy link
Collaborator

@acl-cqc acl-cqc Dec 3, 2024

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
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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 Shown)

@@ -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
Copy link
Collaborator

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
Copy link
Collaborator

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prettify global type variables for error messages
2 participants