-
Notifications
You must be signed in to change notification settings - Fork 1
refactor: Row parsing #116
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
Changes from all commits
8c3b8fd
fa4a0f8
fed4349
50b2f41
8bc5ce4
7ddc09c
977b810
533ea30
4a3b36b
9059363
a7e8ba3
868db16
49528c5
11229de
3d751e6
921e759
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| module Brat.Checker.SolvePatterns (argProblems, argProblemsWithLeftovers, solve, typeOfEnd) where | ||
| module Brat.Checker.SolvePatterns (argProblems, argProblemsWithLeftovers, solve, typeOfEnd, Solution) where | ||
|
|
||
| import Brat.Checker.Monad | ||
| import Brat.Checker.Helpers | ||
|
|
@@ -40,6 +40,8 @@ import Data.Type.Equality ((:~:)(..), testEquality) | |
| -- N.B. we make no assumptions about the values and types being normalised wrt `endVals` | ||
| type Problem = [({-Int,-} Src, Pattern)] -- let's not do fiddly positional arithmetic on the fly | ||
|
|
||
| type Solution m = [(String, (Src, BinderType m))] | ||
|
|
||
| typeOfSrc my src = typeOfEnd my (ExEnd (end src)) | ||
|
|
||
| -- Solve is given a `Problem` (a mapping from wires to patterns) and uses this | ||
|
|
@@ -59,7 +61,7 @@ solve :: forall m. Modey m | |
| -> Problem | ||
| -> Checking (-- [(Int, Test)] -- too much too hugr too soon? | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Drop this commented-out bit while you're here? |
||
| [(Src, PrimTest (BinderType m))] | ||
| ,[(String, (Src, BinderType m))] -- Remember the names given by programmers | ||
| ,Solution m -- Remember the names given by programmers | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might wanna put this comment by the definition of solution, or at least, put something there explaining what |
||
| ) | ||
| solve _ [] = pure ([], []) | ||
| solve my ((src, DontCare):p) = do | ||
|
|
@@ -145,7 +147,7 @@ solveConstructor :: EvMode m | |
| -> Val Z | ||
| -> Problem | ||
| -> Checking ([(Src, PrimTest (BinderType m))] | ||
| ,[(String, (Src, BinderType m))] | ||
| ,Solution m | ||
| ) | ||
| solveConstructor my src (c, abs) ty p = do | ||
| (CArgs pats _ patRo argRo, (tycon, tyargs)) <- lookupConstructor my c ty | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| module Brat.Elaborator where | ||
|
|
||
| import Control.Monad (forM, (>=>)) | ||
| import Control.Monad ((>=>)) | ||
| import Data.Bifunctor (second) | ||
| import Data.List.NonEmpty (NonEmpty(..)) | ||
| import Data.Map (empty) | ||
|
|
@@ -179,6 +179,7 @@ elaborate' (FAnnotation a ts) = do | |
| (SomeRaw a) <- elaborate a | ||
| a <- assertChk a | ||
| a <- assertNoun a | ||
| ts <- fmap (fmap unWC) <$> elabIO ts | ||
| pure $ SomeRaw' (a ::::: ts) | ||
| elaborate' (FInto a b) = elaborate' (FApp b a) | ||
| elaborate' (FOf n e) = do | ||
|
|
@@ -187,15 +188,25 @@ elaborate' (FOf n e) = do | |
| SomeRaw e <- elaborate e | ||
| e <- assertNoun e | ||
| pure $ SomeRaw' (ROf n e) | ||
| elaborate' (FFn cty) = pure $ SomeRaw' (RFn cty) | ||
| elaborate' (FKernel sty) = pure $ SomeRaw' (RKernel sty) | ||
| elaborate' (FFn cty) = SomeRaw' . RFn . fmap (fmap unWC) <$> elabIO cty | ||
| elaborate' (FKernel cty) = SomeRaw' . RKernel . fmap (fmap unWC) <$> elabSig cty | ||
| elaborate' FIdentity = pure $ SomeRaw' RIdentity | ||
| -- We catch underscores in the top-level elaborate so this case | ||
| -- should never be triggered | ||
| elaborate' FUnderscore = Left (dumbErr (InternalError "Unexpected '_'")) | ||
| elaborate' FFanOut = pure $ SomeRaw' RFanOut | ||
| elaborate' FFanIn = pure $ SomeRaw' RFanIn | ||
|
|
||
| elaborateBratType :: WC (KindOr Flat) -> Either Error (WC (KindOr (Raw Chk Noun))) | ||
| elaborateBratType (WC fc (Left k)) = pure (WC fc (Left k)) | ||
| elaborateBratType (WC fc (Right ty)) = fmap Right <$> elaborateChkNoun (WC fc ty) | ||
|
|
||
| elabSig :: Traversable t => t (TypeRowElem (WC Flat)) -> Either Error (t (TypeRowElem (WC (Raw Chk Noun)))) | ||
| elabSig = traverse (traverse elaborateChkNoun) | ||
|
|
||
| elabIO :: Traversable t => t FlatIO -> Either Error (t (TypeRowElem (WC (KindOr (Raw Chk Noun))))) | ||
| elabIO = traverse (traverse elaborateBratType) | ||
|
|
||
| elabBody :: FBody -> FC -> Either Error (FunBody Raw Noun) | ||
| elabBody (FClauses cs) fc = ThunkOf . WC fc . Clauses <$> traverse elab1Clause cs | ||
| where | ||
|
|
@@ -217,14 +228,17 @@ elabBody FUndefined _ = pure Undefined | |
| elabFunDecl :: FDecl -> Either Error RawFuncDecl | ||
| elabFunDecl d = do | ||
| rc <- elabBody (fnBody d) (fnLoc d) | ||
| sig <- elabIO (fnSig d) | ||
| pure $ FuncDecl | ||
| { fnName = fnName d | ||
| , fnLoc = fnLoc d | ||
| , fnSig = fnSig d | ||
| , fnSig = fmap unWC <$> sig -- sus | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems harmless, I mean we can't really be confused between what has WC and not can we? Why is this
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems strange to be throwing away this information in elaboration...
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the comment go on RawFuncDecl that it's fnSig does not include a WC and should? |
||
| , fnBody = rc | ||
| , fnLocality = fnLocality d | ||
| } | ||
|
|
||
| elabAlias :: FAlias -> Either Error RawAlias | ||
| elabAlias (TypeAlias fc name tys tm) = TypeAlias fc name tys . unWC <$> elaborateChkNoun (WC fc tm) | ||
|
|
||
| elabEnv :: FEnv -> Either Error RawEnv | ||
| elabEnv (ds, x) = (,x,empty) <$> forM ds elabFunDecl | ||
| elabEnv (ds, as) = (,,empty) <$> traverse elabFunDecl ds <*> traverse elabAlias as | ||
Uh oh!
There was an error while loading. Please reload this page.