things
This commit is contained in:
@@ -62,7 +62,7 @@ library
|
||||
, data-default-class >= 0.1.2 && < 0.2
|
||||
, hashable >= 1.4.3 && < 1.5
|
||||
, mtl >= 2.3.1 && < 2.4
|
||||
, text >= 2.0.2 && < 2.1
|
||||
, text >= 2.0.2 && < 2.2
|
||||
, unordered-containers >= 0.2.20 && < 0.3
|
||||
, recursion-schemes >= 5.2.2 && < 5.3
|
||||
, data-fix >= 0.3.2 && < 0.4
|
||||
@@ -89,6 +89,7 @@ library
|
||||
DerivingVia
|
||||
StandaloneDeriving
|
||||
DerivingStrategies
|
||||
BlockArguments
|
||||
|
||||
executable rlpc
|
||||
import: warnings
|
||||
@@ -102,7 +103,7 @@ executable rlpc
|
||||
, mtl >= 2.3.1 && < 2.4
|
||||
, unordered-containers >= 0.2.20 && < 0.3
|
||||
, lens >=5.2.3 && <6.0
|
||||
, text >= 2.0.2 && < 2.1
|
||||
, text >= 2.0.2 && < 2.2
|
||||
|
||||
hs-source-dirs: app
|
||||
default-language: GHC2021
|
||||
|
||||
@@ -27,7 +27,7 @@ module Compiler.RLPC
|
||||
-- ** Lenses
|
||||
, rlpcLogFile, rlpcDFlags, rlpcEvaluator, rlpcInputFiles, rlpcLanguage
|
||||
-- * Misc. MTL-style functions
|
||||
, liftErrorful, hoistRlpcT
|
||||
, liftErrorful, liftMaybe, hoistRlpcT
|
||||
-- * Misc. Rlpc Monad -related types
|
||||
, RLPCOptions(RLPCOptions), IsRlpcError(..), RlpcError(..)
|
||||
, MsgEnvelope(..), Severity(..)
|
||||
@@ -108,6 +108,9 @@ evalRLPCT opt r = runRLPCT r
|
||||
liftErrorful :: (Monad m, IsRlpcError e) => ErrorfulT (MsgEnvelope e) m a -> RLPCT m a
|
||||
liftErrorful e = RLPCT $ lift (fmap liftRlpcError `mapErrorful` e)
|
||||
|
||||
liftMaybe :: (Monad m) => Maybe a -> RLPCT m a
|
||||
liftMaybe m = RLPCT . lift . ErrorfulT . pure $ (m, [])
|
||||
|
||||
hoistRlpcT :: (forall a. m a -> n a)
|
||||
-> RLPCT m a -> RLPCT n a
|
||||
hoistRlpcT f rma = RLPCT $ ReaderT $ \opt ->
|
||||
|
||||
@@ -2,8 +2,6 @@ module Core.Utils
|
||||
( programRhss
|
||||
, programGlobals
|
||||
, isAtomic
|
||||
-- , insertModule
|
||||
, extractProgram
|
||||
, freeVariables
|
||||
)
|
||||
where
|
||||
@@ -30,15 +28,6 @@ isAtomic _ = False
|
||||
|
||||
----------------------------------------------------------------------------------
|
||||
|
||||
-- TODO: export list awareness
|
||||
-- insertModule :: Module b -> Program b -> Program b
|
||||
-- insertModule (Module _ p) = programScDefs %~ (<>m)
|
||||
|
||||
extractProgram :: Module b -> Program b
|
||||
extractProgram (Module _ p) = p
|
||||
|
||||
----------------------------------------------------------------------------------
|
||||
|
||||
freeVariables :: Expr' -> Set Name
|
||||
freeVariables = cata go
|
||||
where
|
||||
|
||||
@@ -116,7 +116,7 @@ floatNonStrictCases g = goE
|
||||
goE e
|
||||
traverse_ goE altBodies
|
||||
pure e'
|
||||
goC (f :$ x) = (:$) <$> goC f <*> goC x
|
||||
goC (App f x) = App <$> goC f <*> goC x
|
||||
goC (Let r bs e) = Let r <$> bs' <*> goE e
|
||||
where bs' = travBs goC bs
|
||||
goC (Lit l) = pure (Lit l)
|
||||
@@ -132,6 +132,7 @@ floatNonStrictCases g = goE
|
||||
& traverse goC
|
||||
& const (pure bs)
|
||||
-- ^ ??? what the fuck?
|
||||
-- ^ 24/02/22: what is this shit lol?
|
||||
|
||||
-- when provided with a case expr, floatCase will float the case into a
|
||||
-- supercombinator of its free variables. the sc is returned along with an
|
||||
|
||||
41
src/Misc/Lift1.hs
Normal file
41
src/Misc/Lift1.hs
Normal file
@@ -0,0 +1,41 @@
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
module Misc.Lift1
|
||||
( Lift1(..)
|
||||
, liftCon, liftCon2, liftCon3
|
||||
, Lift(..)
|
||||
)
|
||||
where
|
||||
--------------------------------------------------------------------------------
|
||||
import Language.Haskell.TH hiding (Type, Name)
|
||||
import Language.Haskell.TH.Syntax hiding (Type, Name)
|
||||
import Language.Haskell.TH.Syntax qualified as TH
|
||||
import Language.Haskell.TH.Quote
|
||||
import Data.Kind qualified
|
||||
import GHC.Generics
|
||||
|
||||
import Data.Fix
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
class Lift1 (f :: Data.Kind.Type -> Data.Kind.Type) where
|
||||
lift1 :: (Quote m, Lift t) => f t -> m Exp
|
||||
|
||||
liftCon :: Quote m => TH.Name -> m Exp -> m Exp
|
||||
liftCon n = fmap (AppE (ConE n))
|
||||
|
||||
liftCon2 :: Quote m => TH.Name -> m Exp -> m Exp -> m Exp
|
||||
liftCon2 n a b = do
|
||||
a' <- a
|
||||
b' <- b
|
||||
pure $ ConE n `AppE` a' `AppE` b'
|
||||
|
||||
liftCon3 :: Quote m => TH.Name -> m Exp -> m Exp -> m Exp -> m Exp
|
||||
liftCon3 n a b c = do
|
||||
a' <- a
|
||||
b' <- b
|
||||
c' <- c
|
||||
pure $ ConE n `AppE` a' `AppE` b' `AppE` c'
|
||||
|
||||
instance Lift1 f => Lift (Fix f) where
|
||||
lift (Fix f) = AppE (ConE 'Fix) <$> lift1 f
|
||||
|
||||
|
||||
Reference in New Issue
Block a user