clean warnings
authorJulien Moutinho <julm+symantic-parser@sourcephile.fr>
Sat, 3 Jul 2021 15:07:57 +0000 (17:07 +0200)
committerJulien Moutinho <julm+symantic-parser@sourcephile.fr>
Sun, 11 Jul 2021 17:44:13 +0000 (19:44 +0200)
16 files changed:
ReadMe.md
parsers/Parsers/Brainfuck/SymanticParser/Grammar.hs
parsers/Parsers/Brainfuck/Types.hs
parsers/Parsers/Nandlang.hs
parsers/Parsers/Utils/Handrolled.hs
src/Language/Haskell/TH/Show.hs
src/Symantic/Parser/Grammar/Combinators.hs
src/Symantic/Parser/Grammar/Optimize.hs
src/Symantic/Parser/Grammar/Production.hs
src/Symantic/Parser/Grammar/View.hs
src/Symantic/Parser/Machine/Generate.hs
src/Symantic/Parser/Machine/Instructions.hs
src/Symantic/Typed/Data.hs
src/Symantic/Typed/Lang.hs
src/Symantic/Typed/Optim.hs
src/Symantic/Typed/View.hs

index bff0fb554d7a3f4ac1a7d77e151f5236df8f6677..dd9034e989cdb9bf92ec6a9d0251aa86c38d4564 100644 (file)
--- a/ReadMe.md
+++ b/ReadMe.md
@@ -6,7 +6,7 @@
 
 - Minimal input length checks ("horizon" checks) required for a successful parsing are factorized using a different static analysis than `ParsleyHaskell`'s "piggy bank" which I've not understood well. This analysis uses [polyfix](http://okmij.org/ftp/Computation/fixed-point-combinators.html#Poly-variadic) to see beyond calls to subroutines.
 
-- No dependency upon GHC plugins: `lift-plugin` and `idioms-plugin`, because those are plugins hence introduce a bit of complexity in the build processes using this parser, but most importantly they are experimental and mostly cosmetics, since they only enable a cleaner usage of the parsing combinators, by lifting Haskell code in `pure` to integrate the `TemplateHaskell` needed. I do not understand them that much and do not feel confortable to maintain them come the day that their authors abandon them.
+- No dependency upon GHC plugins: `lift-plugin`, `idioms-plugin` or `parsley-garnish`. Because those are plugins hence introduce a bit of complexity in the build processes using this parser, but most importantly they are experimental and mostly cosmetics, since they only enable a cleaner usage of the parsing combinators: by quoting an Haskell expression as itself and its `TemplateHaskell` equivalent. I do not understand them that much and do not feel confortable to maintain them come the day that their authors abandon them.
 
 - No dependency upon `dependent-map` by keeping observed sharing inside `def` and `ref` combinators, instead of passing by a `DMap`. And also when introducing the join-points optimization, where fresh `TemplateHaskell` names are also directly used instead of passing by a `DMap`.
 
@@ -14,6 +14,8 @@
 
 - License is `AGPL-3-or-later` not `BSD-3-Clause`.
 
+- Some generated `TemplateHaskell` is followed by golden tests.
+
 ### Main goals
 
 - For me to better understand [ParsleyHaskell](https://github.com/j-mie6/ParsleyHaskell), and find a manageable balance between simplicity of the codebase and features of the parser. And by doing so, challenging and showcasing symantic techniques.
index a530b40a7d24518490bbf0db5ae1425992e069b0..0ca453ef76b1e9bdfc6484ac6a9e7f190907bc23 100644 (file)
@@ -7,11 +7,8 @@ module Parsers.Brainfuck.SymanticParser.Grammar where
 
 import Data.Char (Char)
 import Data.Function ((.))
-import qualified Language.Haskell.TH.Syntax as TH
 import qualified Prelude
-import Data.Functor.Product (Product(..))
 
-import Symantic.Typed.Trans
 import qualified Symantic.Parser as SP
 
 import Parsers.Utils
index 6dc34d7249cb046a8d81c3d309afaf0124440e58..bdabdef3b7e061bc7c6e0bfcde75d63b647dbb6a 100644 (file)
@@ -5,13 +5,9 @@ module Parsers.Brainfuck.Types where
 
 import Control.DeepSeq (NFData)
 import Data.Eq (Eq(..))
-import Data.Function (($), (.))
-import Data.Functor.Identity (Identity(..))
 import GHC.Generics (Generic)
 import Text.Show (Show(..))
-import qualified Language.Haskell.TH as TH
 import qualified Language.Haskell.TH.Syntax as TH
-import Symantic.Parser
 
 data Instruction
   = Forward
index 4822f622df4f8846d1fc822db13c01a7e74f40b9..789b8436b82f1526c7a3cfeb48e6b3ba96b5e069 100644 (file)
@@ -17,7 +17,6 @@ import Data.String (String)
 import qualified Data.Set as Set
 import qualified Data.Text as Text
 
-import Symantic.Typed.Trans
 import qualified Symantic.Parser as P
 import qualified Symantic.Typed.Lang as Prod
 
index 5f619badf389660e8811ec91ee0c7182d9b19f38..a6ae706e28083aac93cb994cf1cca779222ee36f 100644 (file)
@@ -1,7 +1,6 @@
 {-# LANGUAGE TypeFamilies #-}
 module Parsers.Utils.Handrolled where
 
-import Control.Monad (Monad(..), fail)
 import Data.Bool (Bool)
 import Data.Char (Char)
 import Data.Maybe (Maybe(..))
index 1bcd1bc03ffcaf8fe06524937e0dcdc30a0880a3..2c61a8e1999a426532e0ec0ca5ddc66078571157 100644 (file)
@@ -1,9 +1,10 @@
+{-# OPTIONS_GHC -Wno-missing-methods #-} -- For TH.Quasi
 -- | This module enables to 'showCode'
 -- without requiring to be in 'IO'.
 module Language.Haskell.TH.Show where
 
 import Data.Function (($), (.))
-import Data.String (String, IsString(..))
+import Data.String (String)
 import Prelude (Integer, error, succ)
 import Control.Applicative (Applicative(..))
 import Control.Monad (Monad(..))
@@ -22,7 +23,8 @@ runShowQ = (`MT.evalState` 0) . unShowQ
 
 showCode :: TH.CodeQ a -> String
 showCode q = runShowQ $ do
-  TH.runQ (TH.examineCode q) >>= return .  TH.pprint . TH.unType
+  texp <- TH.runQ (TH.examineCode q)
+  return $ TH.pprint $ TH.unType texp
 
 -- | The whole point of ShowQ is to remove the need for IO,
 -- but GHC's 'TH.Quasi' class forces it...
index 333b6b939fa1165d55f2efad76bb858b3ac44168..117e4d6826fbeb87e0830a077ab177be3b5230cd 100644 (file)
@@ -28,10 +28,7 @@ import Data.Char (Char)
 import Data.Either (Either(..))
 import Data.Eq (Eq(..))
 import Data.Ord (Ord(..))
-import Data.Functor (Functor)
-import Data.Functor.Identity (Identity(..))
-import Data.Functor.Product (Product(..))
-import Data.Function ((.), flip, id, const)
+import Data.Function ((.), flip, const)
 import Data.Int (Int)
 import Data.Kind (Type, Constraint)
 import Data.Maybe (Maybe(..))
@@ -44,11 +41,9 @@ import qualified Data.List as List
 import qualified Data.Set as Set
 import qualified Language.Haskell.TH as TH
 import qualified Language.Haskell.TH.Syntax as TH
-import qualified Prelude
 
 import qualified Symantic.Typed.Trans as Sym
 import qualified Symantic.Typed.Lang as Prod
-import qualified Symantic.Typed.View
 import Symantic.Parser.Grammar.Production
 
 -- * Type 'ReprComb'
index 88e142348e5607d11669d97c976311e83c0fbe8a..3d5c19184a2e5f847807d3b3f3ab32035222228d 100644 (file)
@@ -20,11 +20,10 @@ import qualified Data.Foldable as Foldable
 import qualified Data.Functor as Functor
 import qualified Data.List as List
 
-import Symantic.Parser.Grammar.Combinators hiding (code)
+import Symantic.Parser.Grammar.Combinators
 import Symantic.Parser.Grammar.Production
 import Symantic.Typed.Letable
 import Symantic.Typed.Trans
-import qualified Symantic.Parser.Grammar.Production as Prod
 import qualified Symantic.Typed.Data as Prod
 import qualified Symantic.Typed.Lang as Prod
 
index 01ac30bda9a765a5d007c7ad08912f929a96e1ae..b5b7f4c561875d293e85cd29495259d4dece90b3 100644 (file)
@@ -4,16 +4,15 @@
 {-# LANGUAGE StandaloneDeriving #-}
 {-# LANGUAGE DeriveLift #-}
 {-# LANGUAGE UndecidableInstances #-}
+{-# OPTIONS_GHC -fno-warn-orphans #-}
 module Symantic.Parser.Grammar.Production where
 
 import Control.Monad (Monad(..))
-import Data.Bool (Bool(..))
-import Data.Char (Char)
-import Data.Eq (Eq)
 import Data.Functor.Identity (Identity(..))
 import Data.Functor.Product (Product(..))
+import Data.Ord (Ord(..))
 import Prelude (Num(..), undefined)
-import Text.Show (Show(..), showString)
+import Text.Show (Show(..), showParen, showString)
 import Type.Reflection (Typeable)
 import qualified Data.Either as Either
 import qualified Data.Eq as Eq
@@ -21,15 +20,12 @@ import qualified Data.Function as Fun
 import qualified Data.Maybe as Maybe
 import qualified Language.Haskell.TH as TH
 import qualified Language.Haskell.TH.Syntax as TH
+import qualified Language.Haskell.TH.Show as TH
 
 import Symantic.Typed.Data
 import Symantic.Typed.Lang
 import Symantic.Typed.Optim
-import Symantic.Typed.Reify
 import Symantic.Typed.Trans
-import Symantic.Typed.View
-
-import Debug.Trace
 
 type Production = Product
   (SomeData Identity)
@@ -59,7 +55,8 @@ runValue x = runIdentity (trans x)
 runCode :: Production a -> TH.CodeQ a
 runCode = trans
 
--- Missing instances in Language.Haskell.TH
+-- Missing instances in 'Language.Haskell.TH',
+-- needed for 'prodCon'.
 deriving instance TH.Lift TH.OccName
 deriving instance TH.Lift TH.NameFlavour
 deriving instance TH.Lift TH.ModName
@@ -72,7 +69,7 @@ prodCon :: TH.Name -> TH.Q TH.Exp
 prodCon name = do
   info <- TH.reify name
   case info of
-    TH.DataConI n ty _pn ->
+    TH.DataConI n _ty _pn ->
       [| production $(return (TH.ConE n))
            (TH.unsafeCodeCoerce (return (TH.ConE $(TH.lift n)))) |]
 
@@ -81,6 +78,12 @@ instance Trans Production Identity where
 instance Trans Production TH.CodeQ where
   trans (Pair _v (SomeData c)) = trans c
 
+instance Show (SomeData TH.CodeQ a) where
+  -- The 'Trans' constraint contained in 'SomeData'
+  -- is 'TH.CodeQ', hence 'Symantic.Typed.View' cannot be used here.
+  -- Fortunately 'TH.showCode' can be implemented.
+  showsPrec p = showString Fun.. TH.showCode Fun.. trans
+
 instance (Abstractable f, Abstractable g) => Abstractable (Product f g) where
   -- Those 'undefined' are not unreachables by 'f'
   -- but this is the cost to pay for defining this instance.
@@ -101,6 +104,12 @@ instance (Abstractable f, Abstractable g) => Abstractable (Product f g) where
   ($) = Pair ($) ($)
 instance (Num (f a), Num (g a)) => Num (Product f g a) where
   Pair x1 x2 + Pair y1 y2 = Pair (x1 + y1) (x2 + y2)
+  Pair x1 x2 * Pair y1 y2 = Pair (x1 * y1) (x2 * y2)
+  Pair x1 x2 - Pair y1 y2 = Pair (x1 - y1) (x2 - y2)
+  abs (Pair x1 x2) = Pair (abs x1) (abs x2)
+  fromInteger i = Pair (fromInteger i) (fromInteger i)
+  negate (Pair x1 x2) = Pair (negate x1) (negate x2)
+  signum (Pair x1 x2) = Pair (signum x1) (signum x2)
 instance (Eitherable f, Eitherable g) => Eitherable (Product f g) where
   left = Pair left left
   right = Pair right right
@@ -171,3 +180,9 @@ instance Maybeable TH.CodeQ where
   just = [|| Maybe.Just ||]
 instance Num a => Num (TH.CodeQ a) where
   x + y = [|| $$x + $$y||]
+  x * y = [|| $$x * $$y||]
+  x - y = [|| $$x - $$y||]
+  abs x = [|| abs $$x ||]
+  fromInteger i = [|| fromInteger $$(TH.liftTyped i) ||]
+  negate x = [|| negate $$x ||]
+  signum x = [|| signum $$x ||]
index 1ff9d9866bf1348f681b9dc0c0edac66c70c2862..e5040672767a99819a8d3e9bec90d58dbdec9c98 100644 (file)
@@ -8,20 +8,13 @@ import Data.Ord (Ord(..))
 import Data.Semigroup (Semigroup(..))
 import Data.String (String)
 import Data.Tuple (fst)
-import System.IO (IO)
 import Text.Show (Show(..))
 import qualified Data.Functor as Functor
 import qualified Data.HashMap.Strict as HM
 import qualified Data.List as List
 import qualified Data.Tree as Tree
-import qualified Language.Haskell.TH as TH
-import qualified Language.Haskell.TH.Show as TH
-import qualified Language.Haskell.TH.Syntax as TH
 
 import Symantic.Typed.Letable
-import qualified Symantic.Typed.Trans as Sym
-import qualified Symantic.Typed.Data as Sym
-import qualified Symantic.Typed.View as Sym
 import Symantic.Parser.Grammar.Combinators
 import qualified Symantic.Parser.Grammar.Production as Prod
 
@@ -54,7 +47,7 @@ instance CombAlternable (ViewGrammar sN) where
   try x = ViewGrammar $ Tree.Node ("try", "") [unViewGrammar x]
 instance CombApplicable (ViewGrammar sN) where
   _f <$> x = ViewGrammar $ Tree.Node ("<$>", "") [unViewGrammar x]
-  pure a = ViewGrammar $ Tree.Node ("pure " <> TH.showCode (Sym.trans (Prod.prodCode a)), "") []
+  pure a = ViewGrammar $ Tree.Node ("pure " <> show (Prod.prodCode a), "") []
   x <*> y = ViewGrammar $ Tree.Node ("<*>", "") [unViewGrammar x, unViewGrammar y]
   x <* y = ViewGrammar $ Tree.Node ("<*", "") [unViewGrammar x, unViewGrammar y]
   x *> y = ViewGrammar $ Tree.Node ("*>", "") [unViewGrammar x, unViewGrammar y]
index 3186d3bdff444d06475309edd9c6ffd0dc49547b..4ec8599a73757f7dd1b8c78f212afb9ddf5f3169 100644 (file)
@@ -51,9 +51,7 @@ import Symantic.Typed.Optim
 import Symantic.Parser.Grammar.Combinators (Exception(..), Failure(..), SomeFailure(..), inputTokenProxy)
 import Symantic.Parser.Machine.Input
 import Symantic.Parser.Machine.Instructions
-import qualified Symantic.Parser.Grammar.Production as Prod
 import qualified Language.Haskell.TH.HideName as TH
-import qualified Symantic.Typed.Data as Prod
 import qualified Symantic.Typed.Lang as Prod
 
 --import Debug.Trace
@@ -703,7 +701,7 @@ checkHorizon ok = ok
         if checkedHorizon ctx >= 1
         then unGen ok ctx0{checkedHorizon = checkedHorizon ctx - 1}
         else let minHoriz =
-                    either (\err -> 0) id $
+                    either (\_err -> 0) id $
                     minReads $ finalGenAnalysis ctx ok in
           [||
           if $$(moreInput ctx)
index d18bf9372dc980ac57e33596eb95714a104268d0..b0dc87b056f8b12e526173a7ccee26a26faaf123 100644 (file)
@@ -11,24 +11,18 @@ import Data.Either (Either)
 import Data.Eq (Eq(..))
 import Data.Function ((.))
 import Data.Kind (Type)
-import Data.Ord (Ord(..))
 import Data.Set (Set)
-import Text.Show (Show(..), showParen, showString)
+import Text.Show (Show(..))
 import qualified Language.Haskell.TH as TH
-import qualified Language.Haskell.TH.Show as TH
 
 import Symantic.Parser.Grammar
 import Symantic.Parser.Machine.Input
 import qualified Symantic.Typed.Lang as Prod
-import qualified Symantic.Typed.Trans as Sym
 import qualified Symantic.Typed.Data as Sym
 
 -- * Type 'Splice'
 type Splice = Sym.SomeData TH.CodeQ
 
-instance Show (Splice a) where
-  showsPrec p = showParen (p >= 0) . showString . TH.showCode . Sym.trans
-
 splice :: TH.CodeQ a -> Splice a
 splice x = Sym.SomeData (Sym.Var x)
 
index 1a988decdbb2864bd78ec207d70404db6fbd80b8..def3ced7fcac8e08a8b76530015c64e623fc9252 100644 (file)
@@ -1,6 +1,5 @@
 {-# LANGUAGE ConstraintKinds #-}
 {-# LANGUAGE DataKinds #-}
---{-# LANGUAGE RoleAnnotations #-}
 {-# LANGUAGE FlexibleContexts #-}
 {-# LANGUAGE FlexibleInstances #-}
 {-# LANGUAGE GADTs #-}
@@ -9,29 +8,21 @@
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE PatternSynonyms #-}
 {-# LANGUAGE RankNTypes #-}
---{-# LANGUAGE QuantifiedConstraints #-}
 {-# LANGUAGE ScopedTypeVariables #-}
 {-# LANGUAGE StandaloneDeriving #-}
 {-# LANGUAGE TypeApplications #-}
 {-# LANGUAGE TypeFamilies #-}
-{-# LANGUAGE UndecidableInstances #-} -- For Abstractable (SomeData repr)
 {-# LANGUAGE ViewPatterns #-}
 module Symantic.Typed.Data where
 
-import Data.Kind
-import Type.Reflection
-import Data.Char (Char)
+import Data.Kind (Constraint, Type)
+import Type.Reflection (Typeable, (:~~:)(..), eqTypeRep, typeRep)
 import Data.Bool (Bool)
 import Data.Either (Either)
 import Data.Maybe (Maybe)
-import Data.Functor.Identity (Identity(..))
-import Data.String (String)
-import Prelude (undefined)
-import Text.Show (Show(..))
 import qualified Data.Eq as Eq
 import qualified Data.Maybe as Maybe
 import qualified Data.Function as Fun
-import Data.Coerce
 
 import Symantic.Typed.Lang
 import Symantic.Typed.Trans
index 2ba4c50b2cb1984ea7363f605f8422be11877699..d3c45567f0f0b844178be73d92291748ac1f09ab 100644 (file)
@@ -13,13 +13,8 @@ import Data.Char (Char)
 import Data.Bool (Bool(..))
 import Data.Either (Either(..))
 import Data.Eq (Eq)
-import Data.Kind
 import Data.Maybe (Maybe(..))
-import Prelude (undefined)
-import Text.Show (Show(..))
-import qualified Data.Eq as Eq
 import qualified Data.Function as Fun
-import qualified Prelude
 
 import Symantic.Typed.Trans
 
@@ -82,8 +77,11 @@ class Constantable c repr where
     Liftable repr => Constantable c (Output repr) =>
     c -> repr c
   constant = lift Fun.. constant
+bool :: Constantable Bool repr => Bool -> repr Bool
 bool = constant @Bool
+char :: Constantable Char repr => Char -> repr Char
 char = constant @Char
+unit :: Constantable () repr => repr ()
 unit = constant @() ()
 class Eitherable repr where
   left :: repr (l -> Either l r)
@@ -103,6 +101,7 @@ class Equalable repr where
     Eq a => repr (a -> a -> Bool)
   equal = lift equal
 infix 4 `equal`, ==
+(==) :: (Abstractable repr, Equalable repr, Eq a) => repr (a -> a -> Bool)
 (==) = lam (\x -> lam (\y -> equal .@ x .@ y))
 class Listable repr where
   cons :: repr (a -> [a] -> [a])
index 869fe776cfb1cd772a951f830a3c073d7752be18..acf1f20c7ce08ea211402bf63db7aa0aa0edd63e 100644 (file)
@@ -1,32 +1,6 @@
-{-# LANGUAGE DataKinds #-}
-{-# LANGUAGE FlexibleContexts #-}
-{-# LANGUAGE FlexibleInstances #-}
-{-# LANGUAGE KindSignatures #-}
-{-# LANGUAGE LambdaCase #-}
-{-# LANGUAGE MultiParamTypeClasses #-}
-{-# LANGUAGE PatternSynonyms #-}
-{-# LANGUAGE QuantifiedConstraints #-}
-{-# LANGUAGE RankNTypes #-}
-{-# LANGUAGE ScopedTypeVariables #-}
-{-# LANGUAGE TypeApplications #-}
-{-# LANGUAGE TypeFamilies #-}
-{-# LANGUAGE UndecidableInstances #-}
-{-# LANGUAGE ViewPatterns #-}
 module Symantic.Typed.Optim where
 
-import Data.Kind
-import Type.Reflection
-import Data.Char (Char)
-import Data.Bool (Bool(..))
-import Data.Maybe (Maybe(..))
-import Data.Functor.Identity (Identity(..))
-import Data.String (String)
-import Prelude (undefined)
-import Text.Show (Show(..))
-import qualified Data.Eq as Eq
 import qualified Data.Function as Fun
-
-import Symantic.Typed.Trans
 import Symantic.Typed.Lang
 import Symantic.Typed.Data
 
index e9886c8ce9f660784e49ebe9ca3a9c8e81812a1c..ba1aa899cc08a51c1c11e3361b0fb3c1246d565c 100644 (file)
 {-# LANGUAGE TypeFamilies #-}
 {-# LANGUAGE UndecidableInstances #-} -- For Show (SomeData a)
 module Symantic.Typed.View where
-{-
+
 import Data.Int (Int)
-import Data.Semigroup (Semigroup(..))
 import Data.String
-import Prelude (undefined)
 import Text.Show
-import Type.Reflection (Typeable)
 import qualified Data.Function as Fun
 import qualified Prelude
 
@@ -33,8 +30,9 @@ data View a where
   ViewApp :: View (b -> a) -> View b -> View a
 
 runView :: View a -> ViewEnv -> ShowS
-runView (View f) env = f env
-runView (ViewInfix _op name _infixName) env = showString name
+runView (View v) env = v env
+runView (ViewInfix _op name _infixName) _env = showString name
+runView (ViewUnifix _op name _unifixName) _env = showString name
 runView (ViewApp f x) env =
   pairView env op Fun.$
     runView f env{viewEnv_op = (op, SideL) } Fun..
@@ -49,11 +47,11 @@ instance Trans View View where
 instance IsString (View a) where
   fromString s = View Fun.$ \_env -> showString s
 instance Show (View a) where
-  showsPrec p (View v) = v ViewEnv
+  showsPrec p = (`runView` ViewEnv
     { viewEnv_op = (infixN p, SideL)
     , viewEnv_pair = pairParen
     , viewEnv_lamDepth = 1
-    }
+    })
 instance Show (SomeData View a) where
   showsPrec p (SomeData x) = showsPrec p (trans @_ @View x)
 
@@ -115,4 +113,3 @@ instance Listable View where
 instance Maybeable View where
   nothing = "Nothing"
   just = "Just"
--}