GithubHelp home page GithubHelp logo

blamario / grampa Goto Github PK

View Code? Open in Web Editor NEW
36.0 36.0 13.0 1.75 MB

Grammatical parsers - combinator library for parsing general context-free grammars

License: BSD 2-Clause "Simplified" License

Haskell 100.00%

grampa's People

Contributors

agreif avatar blamario avatar clintonmead avatar endgame avatar felixonmars avatar jashweii avatar quickdudley avatar tomsmalley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

grampa's Issues

Traversable compositions

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.

QuickCheck timeout - monoid:mconcat

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.

Generated Traversable instance seems to not traverse over structure

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)

Unusual definition of `distributeM`

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.

Consider dropping Product

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.

Build failure with GHC 9.0

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

Metadata revision, or new release?

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?

incompatible with GHC 9.8

 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

New releases?

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.