-
Notifications
You must be signed in to change notification settings - Fork 219
[#1392] Injecting Data.Map #1412
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
Conversation
You can benchmark this if you want. I'm not sure. I believe the current version is easier to understand and should compile faster. |
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.
What's up with the update to the submodule?
dhall/src/Dhall.hs
Outdated
declaredOut = App List $ Record $ Dhall.Map.fromList | ||
[("mapKey", declaredK), ("mapValue", declaredV)] | ||
|
||
mapEntries = fmap recordPair . Data.Sequence.fromList . Data.Map.toList |
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 have a hunch that this would be more efficient, but no proof… :/
mapEntries = fmap recordPair . Data.Sequence.fromList . Data.Map.toList | |
mapEntries = Data.Sequence.fromList . map recordPair . Data.Map.toList |
dhall/src/Dhall.hs
Outdated
| Data.Map.null m = Just declaredOut | ||
| otherwise = Nothing | ||
|
||
declaredOut = App List $ Record $ Dhall.Map.fromList |
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.
So far the code base mostly uses parentheses instead of $
. @Gabriel439 can probably explain why.
I think we should stick with the convention unless there's a good reason not to.
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.
It comes from this: http://www.haskellforall.com/2015/09/how-to-make-your-haskell-code-more.html
... although I usually only apply that to my own coding style. I usually do not review other people's code for style that much
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.
Interesting read, thank you!
I don't know what's up with the submodule either, I've never used one before, it keeps sneaking in and it doesn't really show in I posted in the issue, but do you know what I can do about the |
This should work:
I've responded in the issue. |
I've added a property test. There are so many tests in the project, I'm not sure where I should have placed mine, let me know if I should move it. By the way, while I was playing with it, I saw the property fail for |
dhall/tests/Dhall/Test/QuickCheck.hs
Outdated
@@ -432,6 +439,12 @@ normalizingAnExpressionDoesntChangeItsInferredType expression = | |||
filterOutEmbeds :: Typer a | |||
filterOutEmbeds _ = Const Sort -- This could be any ill-typed expression. | |||
|
|||
injectThenInterpretIsIdentity :: (Inject a, Interpret a, Eq a) => a -> Property |
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.
If you add a Typeable
constraint to this then you can have this generate not only the Property
, but the description, too:
injectThenInterpretIsIdentity a =
( "Injecting then Interpreting is identity for " <> show (typeOf a)
, property
, QuickCheckTests 100
)
where
property = monadicIO $ do …
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.
Oooh, tasty :) (no pun intended)
dhall/src/Dhall.hs
Outdated
@@ -1860,6 +1857,34 @@ instance Inject a => Inject (Data.HashSet.HashSet a) where | |||
|
|||
instance (Inject a, Inject b) => Inject (a, b) | |||
|
|||
{-| Inject a `Data.Map` to a @Prelude.Map.Type@ | |||
|
|||
>>> prettyExpr $ embed inject (Data.Map.fromList [(1 :: Integer, True )]) |
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.
Usually for examples I try to use Natural
instead of Integer
(to encourage more people to use Natural
)
Error in the automated tests:
Suggestions? :( More:
Should I just not use |
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.
👍 Very nice tests!
dhall/tests/Dhall/Test/QuickCheck.hs
Outdated
@@ -56,6 +66,7 @@ import qualified Dhall.Map | |||
import qualified Dhall.Set | |||
import qualified Dhall.TypeCheck | |||
import qualified Generic.Random | |||
import qualified GHC.Natural as GHCNat |
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.
The docs for that module say:
Note: This is an internal GHC module with an API subject to change. It's recommended use the Numeric.Natural module to import the Natural type.
import qualified GHC.Natural as GHCNat | |
import qualified Numeric.Natural |
dhall/tests/Dhall/Test/QuickCheck.hs
Outdated
) | ||
where | ||
prop a = monadicIO $ do | ||
a' <- run . input auto . Text.pack . show . prettyExpr . embed inject $ a |
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.
Why do you pretty-print and re-parse the embedded expressions?
I you'd simply extract
the embed
ded Expr
, we wouldn't need IO
…
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.
Oh man... I feel I'm doing so many obvious mistakes. Thank you!
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.
No worries! :)
Co-Authored-By: Simon Jakobi <[email protected]>
Co-Authored-By: Simon Jakobi <[email protected]>
Fixes #1392
To do:
instance Inject (Data.Map.Map k v)
== id
)Data.Map Text v
embedded as record vianewtype RecordMap
Question: I made two implementations (in my first two commits), one using
Generic
, and an explicit one. Is there a difference in efficiency? The first looks cooler to me.