hasklepias 0.7.0 → 0.7.1
raw patch · 4 files changed
+33/−11 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Hasklepias.Types.Feature: instance (GHC.Show.Show b, GHC.Show.Show d) => GHC.Show.Show (Hasklepias.Types.Feature.Feature d b)
+ Hasklepias.Types.Feature: define1d :: (e -> FeatureData d) -> FeatureDefinition * e d
+ Hasklepias.Types.Feature: instance (GHC.Show.Show b, GHC.Show.Show d) => GHC.Show.Show (Hasklepias.Types.Feature.Feature b d)
Files
- ChangeLog.md +4/−0
- examples/ExampleFeatures1.hs +2/−1
- hasklepias.cabal +1/−1
- src/Hasklepias/Types/Feature.hs +26/−9
ChangeLog.md view
@@ -1,5 +1,9 @@ # Changelog for hasklepias +## 0.7.1++* Fixes bug in `FeatureData` `Monad` instance, so you don't get infinite recursion.+ ## 0.7.0 * Modifies the way that `Feature`s are defined and evaluated. For one, the dependency between `Events` and `Feature`s is eliminated, thus decoupling the defining of Features from the input data type. There are now 4 functions for defining features:
examples/ExampleFeatures1.hs view
@@ -161,7 +161,8 @@ , FeatureData (Maybe (Int, Int)) ) getUnitFeatures x = (- indexDef x+ -- indexDef x+ evs >>= indexDef , liftA2 (enrolledDef 8) (bline x) evs , liftA2 duckHxDef (bline x) evs , liftA2 macawHxDef (bline x) evs
hasklepias.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: hasklepias-version: 0.7.0+version: 0.7.1 description: Please see the README on GitHub at <https://github.com/novisci/asclepias#readme> homepage: https://github.com/novisci/asclepias/#readme bug-reports: https://github.com/novisci/asclepias/issues
src/Hasklepias/Types/Feature.hs view
@@ -11,9 +11,10 @@ {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE Safe #-} {-# LANGUAGE FlexibleInstances #-}- {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE OverloadedStrings #-}+ module Hasklepias.Types.Feature( -- * Types FeatureSpec(..)@@ -26,6 +27,7 @@ , featureDataL , define0 , define1+ , define1d , define2 , define2d , eval0@@ -40,11 +42,11 @@ import safe GHC.Show ( Show(show) ) import safe GHC.Generics ( Generic, D ) import safe Control.Applicative ( Applicative(..) )-import safe Control.Monad ( Functor(..), Monad(..), join, liftM2)+import safe Control.Monad ( Functor(..), Monad(..), join, liftM, liftM2) import safe Data.Either ( Either(..) ) import safe Data.Eq ( Eq ) import safe Data.Function ( ($), (.) )-import safe Data.List ( (++) ) +import safe Data.List ( (++) ) import safe Data.Maybe ( Maybe(..), maybe ) import safe Data.Ord ( Ord ) import safe Data.Text ( Text )@@ -82,7 +84,7 @@ , getData :: FeatureData d } deriving (Eq) -instance (Show b, Show d) => Show (Feature d b) where +instance (Show b, Show d) => Show (Feature b d) where show x = "(" ++ show (getName x) ++ ": (" ++ show (getAttr x) ++ ") " ++ show (getData x) ++ " )\n" instance (Show b) => Functor (Feature b) where@@ -102,8 +104,10 @@ liftA2 f (MkFeatureData x) (MkFeatureData y) = MkFeatureData ( liftA2 f x y ) instance Monad FeatureData where- return = MkFeatureData . return- x >>= f = do x >>= f+ (MkFeatureData x) >>= f = + case fmap f x of+ Left l -> featureDataL l+ Right v -> v -- | Create the 'Right' side of 'FeatureData'. featureDataR :: d -> FeatureData d@@ -121,7 +125,6 @@ | Unknown deriving (Eq, Read, Show, Generic) - -- TODO: the code below should be generalized so that there is a single define/eval -- interface. -- | A type to hold FeatureData definitions; i.e. functions that return @@ -131,32 +134,46 @@ | FD1 (FeatureData e -> FeatureData d) | FD2 (FeatureData f -> FeatureData e -> FeatureData d) +-- | TODO define0 :: (e -> FeatureData d) -> FeatureDefinition * e d define0 = FD0 +-- | TODO eval0 :: FeatureDefinition * e d -> e -> FeatureData d eval0 (FD0 f) = f +-- | TODO evalSpec0 :: (Show b) => FeatureSpec b * e d -> e -> Feature b d evalSpec0 (MkFeatureSpec nm attr def) y = MkFeature nm attr (eval0 def y) +-- | TODO define1 :: (e -> d) -> FeatureDefinition * e d define1 f = FD1 $ fmap f +-- | TODO+define1d :: (e -> FeatureData d) -> FeatureDefinition * e d+define1d f = FD1 (>>= f)++-- | TODO eval1 :: FeatureDefinition * e d -> FeatureData e -> FeatureData d eval1 (FD1 f) = f +-- | TODO evalSpec1 :: (Show b) => FeatureSpec b * e d -> Feature b e -> Feature b d evalSpec1 (MkFeatureSpec nm attr def) y = MkFeature nm attr (eval1 def (getData y)) +-- | TODO define2 :: (f -> e -> d) -> FeatureDefinition f e d define2 f = FD2 $ liftA2 f -define2d :: (f -> e -> FeatureData d) -> FeatureDefinition f e d +-- | TODO+define2d :: (f -> e -> FeatureData d) -> FeatureDefinition f e d define2d f = FD2 (\x y -> join (liftM2 f x y)) +-- | TODO eval2 :: FeatureDefinition f e d -> FeatureData f -> FeatureData e -> FeatureData d-eval2 (FD2 f) = f +eval2 (FD2 f) = f +-- | TODO evalSpec2 :: (Show b) => FeatureSpec b f e d -> Feature b f -> Feature b e -> Feature b d evalSpec2 (MkFeatureSpec nm attr def) y z = MkFeature nm attr (eval2 def (getData y) (getData z))