on master help sign in
GHC 8.4 compatibility

- `-XNoStarIsType` is new in GHC 8.6 - can't use `-XCPP` to conditionally enable `LANGUAGE` pragmas (implicit module declaration) - use a conditional in the .cabal file, but this is active for all modules - need to replace all `*` with `Type` and `import Data.Kind (Type)` (works in 8.4)

commit49a4280a91640ebf698e2c3dfd8768a63fd4f5b4 authorClaude Heiland-Allen <claude@mathr.co.uk> dateFri 14 Dec 2018, 18:00 (8 years ago) parent0bc6bd5
17 files changed+40−30
grenade.cabal+2 src/Grenade/Core/Layer.hs+4−2 src/Grenade/Core/Network.hs+6−4 src/Grenade/Core/Shape.hs−1 src/Grenade/Layers/Concat.hs−1 src/Grenade/Layers/Convolution.hs−1 src/Grenade/Layers/Crop.hs−1 src/Grenade/Layers/Deconvolution.hs−1 src/Grenade/Layers/Merge.hs+3−1 src/Grenade/Layers/Pad.hs−1 src/Grenade/Layers/Pooling.hs−1 src/Grenade/Layers/Reshape.hs−1 src/Grenade/Recurrent/Core/Layer.hs+4−2 src/Grenade/Recurrent/Core/Network.hs+10−8 src/Grenade/Recurrent/Layers/BasicRecurrent.hs+4−2 src/Grenade/Recurrent/Layers/ConcatRecurrent.hs+3−1 src/Grenade/Recurrent/Layers/LSTM.hs+4−2
grenade.cabal+2
@@ -58,6 +58,8 @@ library
5858 if impl(ghc < 8.0)
5959 ghc-options: -fno-warn-incomplete-patterns
6060
61+ if impl(ghc >= 8.6)
62+ default-extensions: NoStarIsType
6163
6264 exposed-modules:
6365 Grenade
src/Grenade/Core/Layer.hs+4−2
@@ -41,6 +41,8 @@ import Control.Monad.Random ( MonadRandom )
4141
4242import Data.List ( foldl' )
4343
44+import Data.Kind (Type)
45+
4446import Grenade.Core.Shape
4547import Grenade.Core.LearningParameters
4648
@@ -50,7 +52,7 @@ import Grenade.Core.LearningParameters
5052class UpdateLayer x where
5153 -- | The type for the gradient for this layer.
5254 -- Unit if there isn't a gradient to pass back.
53− type Gradient x :: *
55+ type Gradient x :: Type
5456
5557 -- | Update a layer with its gradient and learning parameters
5658 runUpdate :: LearningParameters -> x -> Gradient x -> x
@@ -72,7 +74,7 @@ class UpdateLayer x => Layer x (i :: Shape) (o :: Shape) where
7274 -- | The Wengert tape for this layer. Includes all that is required
7375 -- to generate the back propagated gradients efficiently. As a
7476 -- default, `S i` is fine.
75− type Tape x i o :: *
77+ type Tape x i o :: Type
7678
7779 -- | Used in training and scoring. Take the input from the previous
7880 -- layer, and give the output from this layer.
src/Grenade/Core/Network.hs+6−4
@@ -36,6 +36,8 @@ import Data.Singletons
3636import Data.Singletons.Prelude
3737import Data.Serialize
3838
39+import Data.Kind (Type)
40+
3941import Grenade.Core.Layer
4042import Grenade.Core.LearningParameters
4143import Grenade.Core.Shape
@@ -48,7 +50,7 @@ import Grenade.Core.Shape
4850--
4951-- Can be considered to be a heterogeneous list of layers which are able to
5052-- transform the data shapes of the network.
51−data Network :: [*] -> [Shape] -> * where
53+data Network :: [Type] -> [Shape] -> Type where
5254 NNil :: SingI i
5355 => Network '[] '[i]
5456
@@ -66,7 +68,7 @@ instance (Show x, Show (Network xs rs)) => Show (Network (x ': xs) (i ': rs)) wh
6668-- | Gradient of a network.
6769--
6870-- Parameterised on the layers of the network.
69−data Gradients :: [*] -> * where
71+data Gradients :: [Type] -> Type where
7072 GNil :: Gradients '[]
7173
7274 (:/>) :: UpdateLayer x
@@ -77,7 +79,7 @@ data Gradients :: [*] -> * where
7779-- | Wegnert Tape of a network.
7880--
7981-- Parameterised on the layers and shapes of the network.
80−data Tapes :: [*] -> [Shape] -> * where
82+data Tapes :: [Type] -> [Shape] -> Type where
8183 TNil :: SingI i
8284 => Tapes '[] '[i]
8385
@@ -152,7 +154,7 @@ applyUpdate _ NNil GNil
152154
153155-- | A network can easily be created by hand with (:~>), but an easy way to
154156-- initialise a random network is with the randomNetwork.
155−class CreatableNetwork (xs :: [*]) (ss :: [Shape]) where
157+class CreatableNetwork (xs :: [Type]) (ss :: [Shape]) where
156158 -- | Create a network with randomly initialised weights.
157159 --
158160 -- Calls to this function will not compile if the type of the neural
src/Grenade/Core/Shape.hs−1
@@ -8,7 +8,6 @@
88{-# LANGUAGE FlexibleContexts #-}
99{-# LANGUAGE ScopedTypeVariables #-}
1010{-# LANGUAGE RankNTypes #-}
11−{-# LANGUAGE NoStarIsType #-}
1211{-# LANGUAGE UndecidableInstances #-}
1312{-|
1413Module : Grenade.Core.Shape
src/Grenade/Layers/Concat.hs−1
@@ -8,7 +8,6 @@
88{-# LANGUAGE FlexibleInstances #-}
99{-# LANGUAGE ScopedTypeVariables #-}
1010{-# LANGUAGE StandaloneDeriving #-}
11−{-# LANGUAGE NoStarIsType #-}
1211{-# LANGUAGE UndecidableInstances #-}
1312{-|
1413Module : Grenade.Layers.Concat
src/Grenade/Layers/Convolution.hs−1
@@ -8,7 +8,6 @@
88{-# LANGUAGE MultiParamTypeClasses #-}
99{-# LANGUAGE FlexibleInstances #-}
1010{-# LANGUAGE FlexibleContexts #-}
11−{-# LANGUAGE NoStarIsType #-}
1211{-# LANGUAGE UndecidableInstances #-}
1312{-|
1413Module : Grenade.Layers.Convolution
src/Grenade/Layers/Crop.hs−1
@@ -6,7 +6,6 @@
66{-# LANGUAGE TypeFamilies #-}
77{-# LANGUAGE FlexibleContexts #-}
88{-# LANGUAGE MultiParamTypeClasses #-}
9−{-# LANGUAGE NoStarIsType #-}
109{-# LANGUAGE UndecidableInstances #-}
1110{-|
1211Module : Grenade.Layers.Crop
src/Grenade/Layers/Deconvolution.hs−1
@@ -8,7 +8,6 @@
88{-# LANGUAGE MultiParamTypeClasses #-}
99{-# LANGUAGE FlexibleInstances #-}
1010{-# LANGUAGE FlexibleContexts #-}
11−{-# LANGUAGE NoStarIsType #-}
1211{-# LANGUAGE UndecidableInstances #-}
1312{-|
1413Module : Grenade.Layers.Deconvolution
src/Grenade/Layers/Merge.hs+3−1
@@ -23,13 +23,15 @@ import Data.Serialize
2323
2424import Data.Singletons
2525
26+import Data.Kind (Type)
27+
2628import Grenade.Core
2729
2830-- | A Merging layer.
2931--
3032-- Similar to Concat layer, except sums the activations instead of creating a larger
3133-- shape.
32−data Merge :: * -> * -> * where
34+data Merge :: Type -> Type -> Type where
3335 Merge :: x -> y -> Merge x y
3436
3537instance (Show x, Show y) => Show (Merge x y) where
src/Grenade/Layers/Pad.hs−1
@@ -6,7 +6,6 @@
66{-# LANGUAGE TypeFamilies #-}
77{-# LANGUAGE MultiParamTypeClasses #-}
88{-# LANGUAGE FlexibleContexts #-}
9−{-# LANGUAGE NoStarIsType #-}
109{-# LANGUAGE UndecidableInstances #-}
1110{-|
1211Module : Grenade.Core.Pad
src/Grenade/Layers/Pooling.hs−1
@@ -7,7 +7,6 @@
77{-# LANGUAGE TypeFamilies #-}
88{-# LANGUAGE MultiParamTypeClasses #-}
99{-# LANGUAGE FlexibleContexts #-}
10−{-# LANGUAGE NoStarIsType #-}
1110{-# LANGUAGE UndecidableInstances #-}
1211{-|
1312Module : Grenade.Core.Pooling
src/Grenade/Layers/Reshape.hs−1
@@ -3,7 +3,6 @@
33{-# LANGUAGE TypeFamilies #-}
44{-# LANGUAGE MultiParamTypeClasses #-}
55{-# LANGUAGE FlexibleContexts #-}
6−{-# LANGUAGE NoStarIsType #-}
76{-# LANGUAGE UndecidableInstances #-}
87{-|
98Module : Grenade.Layers.Reshape
src/Grenade/Recurrent/Core/Layer.hs+4−2
@@ -8,6 +8,8 @@ module Grenade.Recurrent.Core.Layer (
88 , RecurrentUpdateLayer (..)
99 ) where
1010
11+import Data.Kind (Type)
12+
1113import Grenade.Core
1214
1315-- | Class for a recurrent layer.
@@ -15,11 +17,11 @@ import Grenade.Core
1517-- of an extra recurrent data shape.
1618class UpdateLayer x => RecurrentUpdateLayer x where
1719 -- | Shape of data that is passed between each subsequent run of the layer
18− type RecurrentShape x :: *
20+ type RecurrentShape x :: Type
1921
2022class (RecurrentUpdateLayer x, Num (RecurrentShape x)) => RecurrentLayer x (i :: Shape) (o :: Shape) where
2123 -- | Wengert Tape
22− type RecTape x i o :: *
24+ type RecTape x i o :: Type
2325 -- | Used in training and scoring. Take the input from the previous
2426 -- layer, and give the output from this layer.
2527 runRecurrentForwards :: x -> RecurrentShape x -> S i -> (RecTape x i o, RecurrentShape x, S o)
src/Grenade/Recurrent/Core/Network.hs+10−8
@@ -32,18 +32,20 @@ import Data.Singletons ( SingI )
3232import Data.Singletons.Prelude ( Head, Last )
3333import Data.Serialize
3434
35+import Data.Kind (Type)
36+
3537import Grenade.Core
3638import Grenade.Recurrent.Core.Layer
3739
3840-- | Witness type to say indicate we're building up with a normal feed
3941-- forward layer.
40−data FeedForward :: * -> *
42+data FeedForward :: Type -> Type
4143-- | Witness type to say indicate we're building up with a recurrent layer.
42−data Recurrent :: * -> *
44+data Recurrent :: Type -> Type
4345
4446-- | Type of a recurrent neural network.
4547--
46−-- The [*] type specifies the types of the layers.
48+-- The [Type] type specifies the types of the layers.
4749--
4850-- The [Shape] type specifies the shapes of data passed between the layers.
4951--
@@ -52,7 +54,7 @@ data Recurrent :: * -> *
5254--
5355-- Often, to make the definitions more concise, one will use a type alias
5456-- for these empty data types.
55−data RecurrentNetwork :: [*] -> [Shape] -> * where
57+data RecurrentNetwork :: [Type] -> [Shape] -> Type where
5658 RNil :: SingI i
5759 => RecurrentNetwork '[] '[i]
5860
@@ -71,7 +73,7 @@ infixr 5 :~@>
7173-- | Gradient of a network.
7274--
7375-- Parameterised on the layers of the network.
74−data RecurrentGradient :: [*] -> * where
76+data RecurrentGradient :: [Type] -> Type where
7577 RGNil :: RecurrentGradient '[]
7678
7779 (://>) :: UpdateLayer x
@@ -81,7 +83,7 @@ data RecurrentGradient :: [*] -> * where
8183
8284-- | Recurrent inputs (sideways shapes on an imaginary unrolled graph)
8385-- Parameterised on the layers of a Network.
84−data RecurrentInputs :: [*] -> * where
86+data RecurrentInputs :: [Type] -> Type where
8587 RINil :: RecurrentInputs '[]
8688
8789 (:~~+>) :: (UpdateLayer x, Fractional (RecurrentInputs xs))
@@ -95,7 +97,7 @@ data RecurrentInputs :: [*] -> * where
9597--
9698-- We index on the time step length as well, to ensure
9799-- that that all Tape lengths are the same.
98−data RecurrentTape :: [*] -> [Shape] -> * where
100+data RecurrentTape :: [Type] -> [Shape] -> Type where
99101 TRNil :: SingI i
100102 => RecurrentTape '[] '[i]
101103
@@ -204,7 +206,7 @@ instance (Show x, Show (RecurrentNetwork xs rs)) => Show (RecurrentNetwork (Recu
204206
205207-- | A network can easily be created by hand with (:~~>) and (:~@>), but an easy way to initialise a random
206208-- recurrent network and a set of random inputs for it is with the randomRecurrent.
207−class CreatableRecurrent (xs :: [*]) (ss :: [Shape]) where
209+class CreatableRecurrent (xs :: [Type]) (ss :: [Shape]) where
208210 -- | Create a network of the types requested
209211 randomRecurrent :: MonadRandom m => m (RecurrentNetwork xs ss)
210212
src/Grenade/Recurrent/Layers/BasicRecurrent.hs+4−2
@@ -18,6 +18,8 @@ import Control.Monad.Random ( MonadRandom, getRandom )
1818
1919import Data.Singletons.TypeLits
2020
21+import Data.Kind (Type)
22+
2123import Numeric.LinearAlgebra.Static
2224
2325import GHC.TypeLits
@@ -27,7 +29,7 @@ import Grenade.Recurrent.Core
2729
2830data BasicRecurrent :: Nat -- Input layer size
2931 -> Nat -- Output layer size
30− -> * where
32+ -> Type where
3133 BasicRecurrent :: ( KnownNat input
3234 , KnownNat output
3335 , KnownNat matrixCols
@@ -40,7 +42,7 @@ data BasicRecurrent :: Nat -- Input layer size
4042
4143data BasicRecurrent' :: Nat -- Input layer size
4244 -> Nat -- Output layer size
43− -> * where
45+ -> Type where
4446 BasicRecurrent' :: ( KnownNat input
4547 , KnownNat output
4648 , KnownNat matrixCols
src/Grenade/Recurrent/Layers/ConcatRecurrent.hs+3−1
@@ -27,6 +27,8 @@ import Data.Serialize
2727import Data.Singletons
2828import GHC.TypeLits
2929
30+import Data.Kind (Type)
31+
3032import Grenade.Core
3133import Grenade.Recurrent.Core
3234
@@ -45,7 +47,7 @@ import Numeric.LinearAlgebra.Static ( (#), split, R )
4547--
4648-- 3D images become 3D images with more channels. The sizes must be the same, one can use Pad
4749-- and Crop layers to ensure this is the case.
48−data ConcatRecurrent :: Shape -> * -> Shape -> * -> * where
50+data ConcatRecurrent :: Shape -> Type -> Shape -> Type -> Type where
4951 ConcatRecLeft :: x -> y -> ConcatRecurrent m (Recurrent x) n (FeedForward y)
5052 ConcatRecRight :: x -> y -> ConcatRecurrent m (FeedForward x) n (Recurrent y)
5153 ConcatRecBoth :: x -> y -> ConcatRecurrent m (Recurrent x) n (Recurrent y)
src/Grenade/Recurrent/Layers/LSTM.hs+4−2
@@ -23,6 +23,8 @@ import Data.Proxy
2323import Data.Serialize
2424import Data.Singletons.TypeLits
2525
26+import Data.Kind (Type)
27+
2628import qualified Numeric.LinearAlgebra as LA
2729import Numeric.LinearAlgebra.Static
2830
@@ -36,14 +38,14 @@ import Grenade.Layers.Internal.Update
3638-- This is a Peephole formulation, so the recurrent shape is
3739-- just the cell state, the previous output is not held or used
3840-- at all.
39−data LSTM :: Nat -> Nat -> * where
41+data LSTM :: Nat -> Nat -> Type where
4042 LSTM :: ( KnownNat input
4143 , KnownNat output
4244 ) => !(LSTMWeights input output) -- Weights
4345 -> !(LSTMWeights input output) -- Momentums
4446 -> LSTM input output
4547
46−data LSTMWeights :: Nat -> Nat -> * where
48+data LSTMWeights :: Nat -> Nat -> Type where
4749 LSTMWeights :: ( KnownNat input
4850 , KnownNat output
4951 ) => {