Skip to content
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

Mtl 2.3 fixes #63

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/PureNix/Convert.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

module PureNix.Convert (convert, ModuleInfo (..)) where

import Control.Monad
import Data.Bitraversable
import qualified Data.Map as M
import Data.Set (Set)
Expand Down Expand Up @@ -54,7 +55,7 @@ localSpan :: SourceSpan -> Convert a -> Convert a
localSpan spn = local (fmap $ const spn)

localAnn :: Ann -> Convert a -> Convert a
localAnn (spn, _, _, _) = localSpan spn
localAnn (spn, _, _) = localSpan spn

{-# ANN module' ("hlint: ignore Use list comprehension" :: String) #-}
module' ::
Expand Down Expand Up @@ -106,7 +107,7 @@ expr :: Expr Ann -> Convert N.Expr
expr (Abs ann arg body) = localAnn ann $ fmap (N.lam (N.mkVar arg)) (expr body)
expr (Literal ann lit) = localAnn ann $ literal lit
-- Newtype wrappers can always be removed.
expr (App ann (Var (_, _, _, Just IsNewtype) _) x) = localAnn ann (expr x)
expr (App ann (Var ( _, _, Just IsNewtype) _) x) = localAnn ann (expr x)
expr (App ann f x) = localAnn ann $ liftA2 N.app (expr f) (expr x)
expr (Var ann (P.Qualified mqual name)) = localAnn ann $ do
(_, thisModule, _) <- ask
Expand All @@ -116,7 +117,7 @@ expr (Var ann (P.Qualified mqual name)) = localAnn ann $ do
_ -> N.var (N.mkVar name)
expr (Accessor ann sel body) = localAnn ann $ flip N.sel (N.stringKey sel) <$> expr body
expr (Let ann binds body) = localAnn ann $ liftA2 N.let' (bindings binds) (expr body)
expr (ObjectUpdate ann a b) = localAnn ann $ liftA2 (N.bin N.Update) (expr a) (attrs b)
expr (ObjectUpdate ann a _ b ) = localAnn ann $ liftA2 (N.bin N.Update) (expr a) (attrs b)
expr (Constructor _ _ (P.ProperName dataName) fields) = pure $ N.constructor dataName (N.mkVar <$> fields)
expr (Case ann exprs cases) =
localAnn ann $ do
Expand Down Expand Up @@ -171,7 +172,7 @@ zipBinders exprs binds = mconcat <$> zipWithM unbinder binds exprs
unbinder :: Binder Ann -> N.Expr -> Convert ([N.Expr], [(N.Var, N.Expr)])
unbinder (NullBinder _) _ = pure mempty
unbinder (VarBinder _ name) scrut = pure $ (\name' -> ([], [(name', scrut)])) $ N.mkVar name
unbinder (ConstructorBinder (_, _, _, Just IsNewtype) _ _ [field]) scrut = unbinder field scrut
unbinder (ConstructorBinder ( _, _, Just IsNewtype) _ _ [field]) scrut = unbinder field scrut
unbinder (ConstructorBinder ann _ (P.Qualified _ (P.ProperName tag)) fields) scrut =
localAnn ann $
mappend ([N.bin N.Equals (N.sel scrut "__tag") (N.string tag)], []) . mconcat <$> zipWithM (\binder field -> unbinder binder (N.sel scrut field)) fields (N.numberedKeys "__field")
Expand Down
9 changes: 8 additions & 1 deletion src/PureNix/Expr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ data ExprF f
| Path Text
deriving stock (Functor, Foldable, Traversable, Show)

data Op = Update | Equals | And
-- | Nix binary operators
data Op =
-- | nix @//@ operator (right-side keys overwrite left side attrset)
Update |
-- | nix @==@ operator (equality)
Equals |
-- | nix @&&@ operator (boolean @and@)
And
deriving (Eq, Show)

foldExpr :: (ExprF r -> r) -> Expr -> r
Expand Down
1 change: 1 addition & 0 deletions src/PureNix/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import System.FilePath ((</>))
import qualified System.FilePath as FP
import System.IO
import Control.Monad

Check warning on line 20 in src/PureNix/Main.hs

View workflow job for this annotation

GitHub Actions / Cabal GHC 9.2.3 on ubuntu-latest

The import of ‘Control.Monad’ is redundant

Check warning on line 20 in src/PureNix/Main.hs

View workflow job for this annotation

GitHub Actions / Cabal GHC 9.2.3 on macos-latest

The import of ‘Control.Monad’ is redundant

defaultMain :: IO ()
defaultMain = do
Expand Down
Loading