Skip to content

Commit

Permalink
Merge branch 'release-v0.2.0'
Browse files Browse the repository at this point in the history
* release-v0.2.0:
  Bump versions and update changelog
  Generate COMPLETE pragma for pattern synonyms in mkFreeFoil
  • Loading branch information
fizruk committed Oct 27, 2024
2 parents 97ee040 + 083f176 commit bb8d08c
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .ghci
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:set -XOverloadedStrings
:set -XDataKinds
import qualified Language.SOAS.Impl as SOAS
6 changes: 6 additions & 0 deletions haskell/free-foil/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG for `free-foil`

# 0.2.0 — 2024-10-27

- Generate [`COMPLETE` pragma](https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/pragmas.html#complete-pragmas) in `mkPatternSynonyms` (see [#26](https://github.com/fizruk/free-foil/pull/26))
- Polykind `ZipMatchK` class with default generic implementation via [`kind-generics`](https://hackage.haskell.org/package/kind-generics) (see [#27](https://github.com/fizruk/free-foil/pull/27))
- New experimental TH generation for Free Foil with support for rich syntax in `Control.Monad.Free.Foil.TH.MkFreeFoil` (see [#28](https://github.com/fizruk/free-foil/pull/28))

# 0.1.0 — 2024-08-18

- Generalize functions for binders, support general patterns (see [#16](https://github.com/fizruk/free-foil/pull/16))
Expand Down
2 changes: 1 addition & 1 deletion haskell/free-foil/free-foil.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cabal-version: 1.12
-- see: https://github.com/sol/hpack

name: free-foil
version: 0.1.0
version: 0.2.0
synopsis: Efficient Type-Safe Capture-Avoiding Substitution for Free (Scoped Monads)
description: Please see the README on GitHub at <https://github.com/fizruk/free-foil#readme>
category: Parsing
Expand Down
2 changes: 1 addition & 1 deletion haskell/free-foil/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: free-foil
version: 0.1.0
version: 0.2.0
github: "fizruk/free-foil"
license: BSD3
author: "Nikolai Kudasov"
Expand Down
14 changes: 9 additions & 5 deletions haskell/free-foil/src/Control/Monad/Free/Foil/TH/MkFreeFoil.hs
Original file line number Diff line number Diff line change
Expand Up @@ -521,10 +521,10 @@ termConToPatQuantified config@FreeFoilConfig{..} = go
ForallC _params _ctx con -> go con
RecGadtC conNames argTypes retType -> go (GadtC conNames (map removeName argTypes) retType)

mkPatternSynonym :: Name -> FreeFoilConfig -> FreeFoilTermConfig -> Type -> Con -> Q [Dec]
mkPatternSynonym :: Name -> FreeFoilConfig -> FreeFoilTermConfig -> Type -> Con -> Q [(Name, [Dec])]
mkPatternSynonym rawTypeName config termConfig@FreeFoilTermConfig{..} rawRetType = go
where
go :: Con -> Q [Dec]
go :: Con -> Q [(Name, [Dec])]
go = \case
GadtC conNames rawArgTypes _rawRetType -> concat <$> do
forM (conNames \\ [rawVarConName]) $ \conName -> do
Expand All @@ -537,10 +537,10 @@ mkPatternSynonym rawTypeName config termConfig@FreeFoilTermConfig{..} rawRetType
[(vars, pat, _, _)] <- termConToPat rawTypeName config termConfig (GadtC [conName] rawArgTypes rawRetType) -- FIXME: unsafe matching!
addModFinalizer $ putDoc (DeclDoc patName)
("/Generated/ with '" ++ show 'mkFreeFoil ++ "'. Pattern synonym for an '" ++ show ''Foil.AST ++ "' node of type '" ++ show conName ++ "'.")
return
return [(patName,
[ PatSynSigD patName (toFreeFoilType SortTerm config outerScope innerScope rawConType)
, PatSynD patName (PrefixPatSyn vars) ImplBidir pat
]
])]

NormalC conName types -> go (GadtC [conName] types rawRetType)
RecC conName types -> go (NormalC conName (map removeName types))
Expand Down Expand Up @@ -624,7 +624,11 @@ mkFreeFoil config@FreeFoilConfig{..} = concat <$> sequence
mkPatternSynonyms' FreeFoilTermConfig{..} rawName = do
(tvars, cons) <- reifyDataOrNewtype rawName
let rawRetType = PeelConT rawName (map (VarT . tvarName) tvars)
concat <$> mapM (mkPatternSynonym rawName config FreeFoilTermConfig{..} rawRetType) cons
(unzip -> (patNames, decls)) <- concat <$> mapM (mkPatternSynonym rawName config FreeFoilTermConfig{..} rawRetType) cons
let completeDecl
| rawName == rawTermName = PragmaD (CompleteP ('Foil.Var : patNames) Nothing)
| otherwise = PragmaD (CompleteP patNames Nothing)
return (concat decls ++ [completeDecl])

mkQuantifiedType rawName = do
(tvars, cons) <- reifyDataOrNewtype rawName
Expand Down
10 changes: 5 additions & 5 deletions haskell/lambda-pi/lambda-pi.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cabal-version: 1.24
-- see: https://github.com/sol/hpack

name: lambda-pi
version: 0.1.0
version: 0.2.0
synopsis: λΠ-calculus implemented in a few different ways.
description: Please see the README on GitHub at <https://github.com/fizruk/free-foil#readme>
category: Language
Expand Down Expand Up @@ -60,7 +60,7 @@ library
, bifunctors
, containers
, deepseq
, free-foil >=0.1.0
, free-foil >=0.2.0
, kind-generics-th
, template-haskell
, text >=1.2.3.1
Expand All @@ -84,7 +84,7 @@ executable lambda-pi
, bifunctors
, containers
, deepseq
, free-foil >=0.1.0
, free-foil >=0.2.0
, kind-generics-th
, lambda-pi
, template-haskell
Expand All @@ -110,7 +110,7 @@ test-suite doctests
, containers
, deepseq
, doctest-parallel
, free-foil >=0.1.0
, free-foil >=0.2.0
, kind-generics-th
, lambda-pi
, template-haskell
Expand Down Expand Up @@ -139,7 +139,7 @@ test-suite spec
, bifunctors
, containers
, deepseq
, free-foil >=0.1.0
, free-foil >=0.2.0
, hspec
, hspec-discover
, kind-generics-th
Expand Down
4 changes: 2 additions & 2 deletions haskell/lambda-pi/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: lambda-pi
version: 0.1.0
version: 0.2.0
github: "fizruk/free-foil"
license: BSD3
author: "Nikolai Kudasov"
Expand Down Expand Up @@ -39,7 +39,7 @@ dependencies:
bifunctors:
template-haskell:
deepseq:
free-foil: ">= 0.1.0"
free-foil: ">= 0.2.0"
kind-generics-th:

ghc-options:
Expand Down
4 changes: 2 additions & 2 deletions haskell/soas/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: soas
version: 0.1.0
version: 0.2.0
github: "fizruk/free-foil"
license: BSD3
author: "Nikolai Kudasov"
Expand Down Expand Up @@ -39,7 +39,7 @@ dependencies:
bifunctors:
template-haskell:
deepseq:
free-foil: ">= 0.1.0"
free-foil: ">= 0.2.0"
kind-generics-th:

ghc-options:
Expand Down
10 changes: 5 additions & 5 deletions haskell/soas/soas.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cabal-version: 1.24
-- see: https://github.com/sol/hpack

name: soas
version: 0.1.0
version: 0.2.0
synopsis: Second-Order Abstract Syntax implemented via Free Foil (a version of SOAS).
description: Please see the README on GitHub at <https://github.com/fizruk/free-foil#readme>
category: Language
Expand Down Expand Up @@ -58,7 +58,7 @@ library
, bifunctors
, containers
, deepseq
, free-foil >=0.1.0
, free-foil >=0.2.0
, kind-generics-th
, template-haskell
, text >=1.2.3.1
Expand All @@ -82,7 +82,7 @@ executable soas
, bifunctors
, containers
, deepseq
, free-foil >=0.1.0
, free-foil >=0.2.0
, kind-generics-th
, soas
, template-haskell
Expand All @@ -108,7 +108,7 @@ test-suite doctests
, containers
, deepseq
, doctest-parallel
, free-foil >=0.1.0
, free-foil >=0.2.0
, kind-generics-th
, soas
, template-haskell
Expand All @@ -135,7 +135,7 @@ test-suite spec
, bifunctors
, containers
, deepseq
, free-foil >=0.1.0
, free-foil >=0.2.0
, hspec
, hspec-discover
, kind-generics-th
Expand Down
4 changes: 3 additions & 1 deletion haskell/soas/src/Language/SOAS/Impl.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# OPTIONS_GHC -Wno-orphans -Wno-redundant-constraints -ddump-splices #-}
{-# OPTIONS_GHC -Wno-orphans -Wno-redundant-constraints #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
Expand All @@ -17,6 +17,7 @@
-- represented using scope-safe Haskell types (via Free Foil).
module Language.SOAS.Impl where


import Data.List (find)
import Data.Bifunctor
import qualified Control.Monad.Foil as Foil
Expand Down Expand Up @@ -68,6 +69,7 @@ applySubsts scope substs term =
MetaVar _loc m args | Just (Subst _ _ binders body) <- lookupSubst m substs ->
substitutePattern scope Foil.voidSubst binders args body
Var{} -> term
-- NOTE: generic recursive processing!
Node node -> Node (bimap goScoped (applySubsts scope substs) node)
where
goScoped (ScopedAST binders body) =
Expand Down

0 comments on commit bb8d08c

Please sign in to comment.