-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This also fixes `Fix` and adds `Cofix`. And adds some more strict functors.
- Loading branch information
Showing
15 changed files
with
310 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{-# LANGUAGE TemplateHaskell #-} | ||
|
||
module Test.Fold.Native where | ||
|
||
import "base" Control.Category (Category (id)) | ||
import "base" Control.Monad ((=<<)) | ||
import "base" Data.Bool (Bool) | ||
import "base" Data.Function (($)) | ||
import "base" Data.Proxy (Proxy (Proxy)) | ||
import "base" System.IO (IO) | ||
import "hedgehog" Hedgehog (Property, checkParallel, discover, forAll, property) | ||
import qualified "hedgehog" Hedgehog.Gen as Gen | ||
import "yaya" Yaya.Fold.Common (size) | ||
import "yaya" Yaya.Fold.Native (Fix) | ||
import "yaya-hedgehog" Yaya.Hedgehog.Expr (Expr, genExpr, genFixExpr) | ||
import "yaya-hedgehog" Yaya.Hedgehog.Fold | ||
( law_cataCancel, | ||
law_cataCompose, | ||
law_cataRefl, | ||
) | ||
|
||
-- TODO: For some reason HLint is complaining that TemplateHaskell is unused. | ||
{-# ANN module "HLint: ignore Unused LANGUAGE pragma" #-} | ||
|
||
prop_fixCataCancel :: Property | ||
prop_fixCataCancel = | ||
property $ law_cataCancel size =<< forAll (genExpr (Gen.sized genFixExpr)) | ||
|
||
prop_fixCataRefl :: Property | ||
prop_fixCataRefl = | ||
property $ law_cataRefl =<< forAll (Gen.sized genFixExpr) | ||
|
||
prop_fixCataCompose :: Property | ||
prop_fixCataCompose = | ||
property $ | ||
law_cataCompose (Proxy :: Proxy (Fix Expr)) size id | ||
=<< forAll (Gen.sized genFixExpr) | ||
|
||
tests :: IO Bool | ||
tests = checkParallel $$discover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
-- NB: We disable @StrictData@ here in order for `Cofix` to be lazy. I don’t | ||
-- think there is any way to explicitly add @~@ patterns that has the | ||
-- correct semantics. | ||
{-# LANGUAGE NoStrictData #-} | ||
|
||
-- | This module only exists to restrict the scope of @NoStrictData@. Everything | ||
-- is re-exported via "Yaya.Fold". | ||
module Yaya.Fold.Native.Internal where | ||
|
||
import "base" Control.Category (Category ((.))) | ||
import "base" Data.Functor (Functor (fmap)) | ||
import "this" Yaya.Fold | ||
( Corecursive (ana), | ||
Projectable (project), | ||
Steppable (embed), | ||
) | ||
|
||
-- | A fixed-point constructor that uses Haskell's built-in recursion. This is | ||
-- lazy/corecursive. | ||
data Cofix f = Cofix {unCofix :: f (Cofix f)} | ||
{-# ANN Cofix "HLint: ignore Use newtype instead of data" #-} | ||
|
||
instance Projectable (->) (Cofix f) f where | ||
project = unCofix | ||
|
||
instance Steppable (->) (Cofix f) f where | ||
embed = Cofix | ||
|
||
instance (Functor f) => Corecursive (->) (Cofix f) f where | ||
ana φ = embed . fmap (ana φ) . φ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{-# LANGUAGE NumericUnderscores #-} | ||
|
||
module Yaya.Hedgehog where | ||
|
||
import "base" Control.Category (Category ((.))) | ||
import "base" Control.Monad ((<=<)) | ||
import "base" Control.Monad.IO.Class (MonadIO) | ||
import "base" Data.Function (const) | ||
import "base" Data.Maybe (maybe) | ||
import "base" GHC.IO (evaluate) | ||
import "base" GHC.Stack (HasCallStack) | ||
import "base" System.Timeout (timeout) | ||
import "base" Text.Show (Show) | ||
import "hedgehog" Hedgehog | ||
|
||
-- | Returns success if the expression doesn’t terminate, failure otherwise. | ||
-- Termination is just checked with a 1 second timeout, so this isn’t | ||
-- foolproof. | ||
evalNonterminating :: | ||
(HasCallStack, MonadIO m, MonadTest m, Show a) => a -> m () | ||
evalNonterminating = | ||
maybe success (const failure <=< annotateShow) | ||
<=< evalIO . timeout 1_000_000 . evaluate | ||
|
||
-- | Returns success if the expression doesn’t terminate, failure otherwise. | ||
-- The value passed here should termina | ||
nonterminatingProperty :: (HasCallStack, Show a) => a -> Property | ||
nonterminatingProperty = withTests 1 . property . evalNonterminating |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.