blamario / grampa Goto Github PK
View Code? Open in Web Editor NEWGrammatical parsers - combinator library for parsing general context-free grammars
License: BSD 2-Clause "Simplified" License
Grammatical parsers - combinator library for parsing general context-free grammars
License: BSD 2-Clause "Simplified" License
Unfortunately, there seem to be several ways to make a Traversable
from a composition of two types. Perhaps it would make sense to offer newtypes to cover some of them.
See this nixpkgs comment:
$ ./dist-newstyle/build/x86_64-linux/ghc-8.6.5/grammatical-parsers-0.4.1.1/t/quicktests/build/quicktests/quicktests --quickcheck-replay=83506
...
classes
monoid
...
mconcat: FAIL (1.92s)
*** Failed! Timeout (after 95 tests):
Use --quickcheck-replay=83506 to reproduce.
Lazy instances don't tend to follow laws terribly nicely, and can easily lead to performance problems. Why is it done this way?
Given the program (tested on GHC 9.0.1):
{-# OPTIONS_GHC -ddump-splices #-}
{-# LANGUAGE TemplateHaskell #-}
import Control.Monad.Identity
import Data.Functor.Classes
import qualified Rank2
import qualified Rank2.TH
data Stm r = Unit | ExpStmt (r Int) (Exp r)
data Exp r = Nil | Cons (r Bool) (Exp r) (Stm r)
instance Show1 r => Show (Stm r) where
show Unit = "Unit"
show (ExpStmt r e) = "(Stmt (" ++ showsPrec1 0 r (") " ++ show e ++ ")")
instance Show1 r => Show (Exp r) where
show Nil = "Nil"
show (Cons r e s) =
"(Cons (" ++ showsPrec1 0 r (") " ++ show e ++ " " ++ show s ++ ")")
$(mconcat <$> traverse
(\derive -> mconcat <$> traverse derive [''Stm, ''Exp])
[ Rank2.TH.deriveFunctor
, Rank2.TH.deriveFoldable
, Rank2.TH.deriveTraversable
])
expToMaybe :: Exp Identity -> Exp Maybe
expToMaybe = Rank2.fmap (Just . runIdentity)
maybeToExp :: Exp Maybe -> Maybe (Exp Identity)
maybeToExp = Rank2.traverse (fmap Identity)
myExp :: Exp Identity
myExp = Cons
(Identity True)
(Cons (Identity False) Nil (ExpStmt (Identity 2) Nil))
(ExpStmt (Identity 3) (Cons (Identity True) Nil Unit))
main :: IO ()
main = do
print myExp
let myExp' = expToMaybe myExp
print myExp'
print $ maybeToExp myExp'
It prints the result:
(Cons (Identity True) (Cons (Identity False) Nil (Stmt (Identity 2) Nil)) (Stmt (Identity 3) (Cons (Identity True) Nil Unit)))
(Cons (Just True) (Cons (Just False) Nil (Stmt (Just 2) Nil)) (Stmt (Just 3) (Cons (Just True) Nil Unit)))
Just Nil
It seems like Rank2.traverse
is returning Nil
instead of traversing over the structure. Looking at the generated TH it looks like wildcard patterns are used for single data constructors in the Traversable instance which ignores the rest of the constructors.
mconcat
<$>
traverse
(\ derive_a1fm -> mconcat <$> traverse derive_a1fm [''Stm, ''Exp])
[Rank2.TH.deriveFunctor, Rank2.TH.deriveFoldable,
Rank2.TH.deriveTraversable]
======>
instance Rank2.Functor Stm where
{-# INLINE (Rank2.<$>) #-}
(Rank2.<$>) f_a32G Unit = Unit
(Rank2.<$>) f_a32H (ExpStmt x_a32I x_a32J)
= (ExpStmt (f_a32H x_a32I)) ((f_a32H Rank2.<$>) x_a32J)
instance Rank2.Functor Exp where
{-# INLINE (Rank2.<$>) #-}
(Rank2.<$>) f_a32M Nil = Nil
(Rank2.<$>) f_a32N (Cons x_a32O x_a32P x_a32Q)
= ((Cons (f_a32N x_a32O)) ((f_a32N Rank2.<$>) x_a32P))
((f_a32N Rank2.<$>) x_a32Q)
instance Rank2.Foldable Stm where
{-# INLINABLE Rank2.foldMap #-}
Rank2.foldMap f_a32T Unit = mempty
Rank2.foldMap f_a32U (ExpStmt x_a32V x_a32W)
= (f_a32U x_a32V <> (Rank2.foldMap f_a32U) x_a32W)
instance Rank2.Foldable Exp where
{-# INLINABLE Rank2.foldMap #-}
Rank2.foldMap f_a32Z Nil = mempty
Rank2.foldMap f_a330 (Cons x_a331 x_a332 x_a333)
= (f_a330 x_a331
<>
((Rank2.foldMap f_a330) x_a332 <> (Rank2.foldMap f_a330) x_a333))
instance Rank2.Traversable Stm where
{-# INLINABLE Rank2.traverse #-}
Rank2.traverse _ _ = pure Unit
Rank2.traverse f_a336 (ExpStmt x_a337 x_a338)
= ((ExpStmt <$> f_a336 x_a337) <*> (Rank2.traverse f_a336) x_a338)
instance Rank2.Traversable Exp where
{-# INLINABLE Rank2.traverse #-}
Rank2.traverse _ _ = pure Nil
Rank2.traverse f_a33b (Cons x_a33c x_a33d x_a33e)
= (((Cons <$> f_a33b x_a33c) <*> (Rank2.traverse f_a33b) x_a33d)
<*> (Rank2.traverse f_a33b) x_a33e)
I've noticed that the definition of distributeM
in the package is strange, as it doesn't seem to be the equivalent of distributeM in the distributive package.
distributeM
currently has this signature:
(Distributive g, Rank1.Monad f) => f (g f) -> g f
But I believe it should have this signature:
(Distributive g, Monad m) => m (g p) -> g (Compose m p)
That is, the dual of sequence
.
Perhaps distributeM
should be renamed should be renamed to join
? (Is it the rank to equivalent of join?!). And a new distributeM
created which follows the suggested signature.
Now that Data.Functor.Product.Product
is polykinded, I'm not sure rank2classes
really needs its own. The main difference is that your version has fst
and snd
fields while the one in base
doesn't.
rank2classes 1.5:
[2 of 2] Compiling Rank2.TH ( src/Rank2/TH.hs, dist/build/Rank2/TH.dyn_o )
src/Rank2/TH.hs:582:28: error:
Not in scope: data constructor ‘TH.OverloadedRecordDot’
Module ‘Language.Haskell.TH’ does not export ‘OverloadedRecordDot’.
|
582 | dotty <- TH.isExtEnabled TH.OverloadedRecordDot
| ^^^^^^^^^^^^^^^^^^^^^^
src/Rank2/TH.hs:584:11: error:
Not in scope: ‘TH.projectionE’
Module ‘Language.Haskell.TH’ does not export ‘projectionE’.
|
584 | then TH.projectionE (pure $ TH.nameBase field)
| ^^^^^^^^^^^^^^
src/Rank2/TH.hs:592:28: error:
Not in scope: data constructor ‘TH.OverloadedRecordDot’
Module ‘Language.Haskell.TH’ does not export ‘OverloadedRecordDot’.
|
592 | dotty <- TH.isExtEnabled TH.OverloadedRecordDot
| ^^^^^^^^^^^^^^^^^^^^^^
src/Rank2/TH.hs:594:11: error:
Not in scope: ‘TH.getFieldE’
Module ‘Language.Haskell.TH’ does not export ‘getFieldE’.
|
594 | then TH.getFieldE record (TH.nameBase field)
| ^^^^^^^^^^^^
It seems to have been left out for some reason.
(<$>)
does not have a fixity annotation. Should it?
If there are no new releases planned for the near future, would it be possible to push metadata revisions that declare the dependency on markdown-unlit
?
src/Rank2/TH.hs:118:24: error: [GHC-83865]
• Couldn't match expected type ‘TH.BndrVis’ with actual type ‘()’
• In the pattern: ()
In the pattern: KindedTV tyVar () (AppT (AppT ArrowT _) StarT)
In a pattern binding:
(KindedTV tyVar () (AppT (AppT ArrowT _) StarT)) = last tyVars
|
118 | let (KindedTV tyVar () (AppT (AppT ArrowT _) StarT)) = last tyVars
| ^^
Error: cabal: Failed to build rank2classes-1.5.2 (which is required by
Can we add stack support to the project?
The git commits talk about rank2classes 1.3.1 and grammatical-parsers-0.4.0.1, but they do not seem to be on hackage. Was a candidate uploaded but not published, perhaps?
Citing from https://hydra.nixos.org/build/103546660:
Preprocessing test suite 'doctests' for rank2classes-1.3.1.1..
Building test suite 'doctests' for rank2classes-1.3.1.1..
test/README.lhs:10:8: error:
File name does not match module name:
Saw: ‘MyModule’
Expected: ‘README’
|
10 | module MyModule where
| ^^^^^^^^
rank2classes-1.4.3 fails with
src/Rank2.hs:242:18: error:
• Expected kind ‘(k0 -> *) -> *’,
but ‘Generics.V1’ has kind ‘* -> *’
• In the first argument of ‘Functor’, namely ‘Generics.V1’
In the instance declaration for ‘Functor Generics.V1’
I made a revision https://hackage.haskell.org/package/rank2classes-1.4.3/revisions/
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.