From 9ee755117e85ee45d4b1923bb0dac2173f6625ad Mon Sep 17 00:00:00 2001 From: Joshua Moerman Date: Wed, 22 Jun 2016 17:27:35 +0200 Subject: [PATCH] Adds ways to control strictness. Increases efficiency by 1.5x (if used in observation table) --- NominalAngluin.cabal | 1 + src/Examples/Fifo.hs | 5 +++-- src/ObservationTable.hs | 7 ++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/NominalAngluin.cabal b/NominalAngluin.cabal index a5baee6..e0783ce 100644 --- a/NominalAngluin.cabal +++ b/NominalAngluin.cabal @@ -22,6 +22,7 @@ executable NominalAngluin build-depends: base >=4.8 && <4.9, containers, + deepseq, haskeline, mtl, NLambda diff --git a/src/Examples/Fifo.hs b/src/Examples/Fifo.hs index a3eee88..d38d9db 100644 --- a/src/Examples/Fifo.hs +++ b/src/Examples/Fifo.hs @@ -1,6 +1,7 @@ -{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DeriveGeneric, DeriveAnyClass #-} module Examples.Fifo (DataInput(..), fifoExample) where +import Control.DeepSeq (NFData) import GHC.Generics (Generic) import NLambda import Prelude (Eq, Int, Maybe (..), Ord, Show, length, reverse, @@ -34,7 +35,7 @@ sizeFifo (Fifo l1 l2) = length l1 + length l2 -- nominal automaton. -- The alphabet: -data DataInput = Put Atom | Get Atom deriving (Eq, Ord, Show, Generic) +data DataInput = Put Atom | Get Atom deriving (Eq, Ord, Show, Generic, NFData) instance BareNominalType DataInput instance Contextual DataInput where when f (Put a) = Put (when f a) diff --git a/src/ObservationTable.hs b/src/ObservationTable.hs index 108121e..74dd359 100644 --- a/src/ObservationTable.hs +++ b/src/ObservationTable.hs @@ -1,4 +1,5 @@ {-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE RecordWildCards #-} @@ -14,6 +15,8 @@ import GHC.Generics (Generic) import Prelude (Bool (..), Eq, Ord, Show, ($), (++), (.), uncurry) import qualified Prelude () +import Control.DeepSeq + -- An observation table is a function S x E -> O -- (Also includes SA x E -> O) type Table i o = Fun ([i], [i]) o @@ -53,9 +56,7 @@ data State i = State , ee :: Set [i] -- suffixes , aa :: Set i -- alphabet (remains constant) } - deriving (Show, Ord, Eq, Generic) - -instance NominalType i => BareNominalType (State i) + deriving (Show, Ord, Eq, Generic, NFData, BareNominalType) instance NominalType i => Conditional (State i) where cond f s1 s2 = fromTup (cond f (toTup s1) (toTup s2)) where