on master help sign in
NoStarIsType and UndecidableInstances needed for ghc-8.6

NoStarIsType -- otherwise GHC gets confused about * as a type operator import Data.Kind (Type) -- to replace the usage of * as a type UndecidableInstances -- otherwise GHC complains about nested KnownNat (a * b)

commit0bc6bd5fad90e3edbf0079745fc7bf65069d7152 authorClaude Heiland-Allen <claude@mathr.co.uk> dateFri 14 Dec 2018, 17:30 (8 years ago) parent251a398
9 files changed+31−8
src/Grenade/Core/Shape.hs+2 src/Grenade/Layers/Concat.hs+4−1 src/Grenade/Layers/Convolution.hs+5−2 src/Grenade/Layers/Crop.hs+4−1 src/Grenade/Layers/Deconvolution.hs+5−2 src/Grenade/Layers/Pad.hs+4−1 src/Grenade/Layers/Pooling.hs+4−1 src/Grenade/Layers/Reshape.hs+2 src/Grenade/Recurrent/Layers/ConcatRecurrent.hs+1
src/Grenade/Core/Shape.hs+2
@@ -8,6 +8,8 @@
88{-# LANGUAGE FlexibleContexts #-}
99{-# LANGUAGE ScopedTypeVariables #-}
1010{-# LANGUAGE RankNTypes #-}
11+{-# LANGUAGE NoStarIsType #-}
12+{-# LANGUAGE UndecidableInstances #-}
1113{-|
1214Module : Grenade.Core.Shape
1315Description : Dependently typed shapes of data which are passed between layers of a network
src/Grenade/Layers/Concat.hs+4−1
@@ -8,6 +8,8 @@
88{-# LANGUAGE FlexibleInstances #-}
99{-# LANGUAGE ScopedTypeVariables #-}
1010{-# LANGUAGE StandaloneDeriving #-}
11+{-# LANGUAGE NoStarIsType #-}
12+{-# LANGUAGE UndecidableInstances #-}
1113{-|
1214Module : Grenade.Layers.Concat
1315Description : Concatenation layer
@@ -25,6 +27,7 @@ import Data.Serialize
2527
2628import Data.Singletons
2729import GHC.TypeLits
30+import Data.Kind (Type)
2831
2932import Grenade.Core
3033
@@ -43,7 +46,7 @@ import Numeric.LinearAlgebra.Static ( row, (===), splitRows, unrow, (#
4346--
4447-- 3D images become 3D images with more channels. The sizes must be the same, one can use Pad
4548-- and Crop layers to ensure this is the case.
46−data Concat :: Shape -> * -> Shape -> * -> * where
49+data Concat :: Shape -> Type -> Shape -> Type -> Type where
4750 Concat :: x -> y -> Concat m x n y
4851
4952instance (Show x, Show y) => Show (Concat m x n y) where
src/Grenade/Layers/Convolution.hs+5−2
@@ -8,6 +8,8 @@
88{-# LANGUAGE MultiParamTypeClasses #-}
99{-# LANGUAGE FlexibleInstances #-}
1010{-# LANGUAGE FlexibleContexts #-}
11+{-# LANGUAGE NoStarIsType #-}
12+{-# LANGUAGE UndecidableInstances #-}
1113{-|
1214Module : Grenade.Layers.Convolution
1315Description : Convolution layer
@@ -35,6 +37,7 @@ import GHC.TypeLits hiding (natVal)
3537#else
3638import GHC.TypeLits
3739#endif
40+import Data.Kind (Type)
3841
3942import Numeric.LinearAlgebra hiding ( uniformSample, konst )
4043import qualified Numeric.LinearAlgebra as LA
@@ -61,7 +64,7 @@ data Convolution :: Nat -- Number of channels, for the first layer this could be
6164 -> Nat -- The number of column in the kernel filter
6265 -> Nat -- The row stride of the convolution filter
6366 -> Nat -- The columns stride of the convolution filter
64− -> * where
67+ -> Type where
6568 Convolution :: ( KnownNat channels
6669 , KnownNat filters
6770 , KnownNat kernelRows
@@ -80,7 +83,7 @@ data Convolution' :: Nat -- Number of channels, for the first layer this could b
8083 -> Nat -- The number of column in the kernel filter
8184 -> Nat -- The row stride of the convolution filter
8285 -> Nat -- The columns stride of the convolution filter
83− -> * where
86+ -> Type where
8487 Convolution' :: ( KnownNat channels
8588 , KnownNat filters
8689 , KnownNat kernelRows
src/Grenade/Layers/Crop.hs+4−1
@@ -6,6 +6,8 @@
66{-# LANGUAGE TypeFamilies #-}
77{-# LANGUAGE FlexibleContexts #-}
88{-# LANGUAGE MultiParamTypeClasses #-}
9+{-# LANGUAGE NoStarIsType #-}
10+{-# LANGUAGE UndecidableInstances #-}
911{-|
1012Module : Grenade.Layers.Crop
1113Description : Cropping layer
@@ -27,6 +29,7 @@ import GHC.TypeLits hiding (natVal)
2729#else
2830import GHC.TypeLits
2931#endif
32+import Data.Kind (Type)
3033
3134import Grenade.Core
3235import Grenade.Layers.Internal.Pad
@@ -38,7 +41,7 @@ import Numeric.LinearAlgebra.Static (extract, create)
3841data Crop :: Nat
3942 -> Nat
4043 -> Nat
41− -> Nat -> * where
44+ -> Nat -> Type where
4245 Crop :: Crop cropLeft cropTop cropRight cropBottom
4346
4447instance Show (Crop cropLeft cropTop cropRight cropBottom) where
src/Grenade/Layers/Deconvolution.hs+5−2
@@ -8,6 +8,8 @@
88{-# LANGUAGE MultiParamTypeClasses #-}
99{-# LANGUAGE FlexibleInstances #-}
1010{-# LANGUAGE FlexibleContexts #-}
11+{-# LANGUAGE NoStarIsType #-}
12+{-# LANGUAGE UndecidableInstances #-}
1113{-|
1214Module : Grenade.Layers.Deconvolution
1315Description : Deconvolution layer
@@ -39,6 +41,7 @@ import GHC.TypeLits hiding (natVal)
3941#else
4042import GHC.TypeLits
4143#endif
44+import Data.Kind (Type)
4245
4346import Numeric.LinearAlgebra hiding ( uniformSample, konst )
4447import qualified Numeric.LinearAlgebra as LA
@@ -60,7 +63,7 @@ data Deconvolution :: Nat -- Number of channels, for the first layer this could
6063 -> Nat -- The number of column in the kernel filter
6164 -> Nat -- The row stride of the Deconvolution filter
6265 -> Nat -- The columns stride of the Deconvolution filter
63− -> * where
66+ -> Type where
6467 Deconvolution :: ( KnownNat channels
6568 , KnownNat filters
6669 , KnownNat kernelRows
@@ -79,7 +82,7 @@ data Deconvolution' :: Nat -- Number of channels, for the first layer this could
7982 -> Nat -- The number of column in the kernel filter
8083 -> Nat -- The row stride of the Deconvolution filter
8184 -> Nat -- The columns stride of the Deconvolution filter
82− -> * where
85+ -> Type where
8386 Deconvolution' :: ( KnownNat channels
8487 , KnownNat filters
8588 , KnownNat kernelRows
src/Grenade/Layers/Pad.hs+4−1
@@ -6,6 +6,8 @@
66{-# LANGUAGE TypeFamilies #-}
77{-# LANGUAGE MultiParamTypeClasses #-}
88{-# LANGUAGE FlexibleContexts #-}
9+{-# LANGUAGE NoStarIsType #-}
10+{-# LANGUAGE UndecidableInstances #-}
911{-|
1012Module : Grenade.Core.Pad
1113Description : Padding layer for 2D and 3D images
@@ -27,6 +29,7 @@ import GHC.TypeLits hiding (natVal)
2729#else
2830import GHC.TypeLits
2931#endif
32+import Data.Kind (Type)
3033
3134import Grenade.Core
3235import Grenade.Layers.Internal.Pad
@@ -40,7 +43,7 @@ import Numeric.LinearAlgebra.Static (extract, create)
4043data Pad :: Nat
4144 -> Nat
4245 -> Nat
43− -> Nat -> * where
46+ -> Nat -> Type where
4447 Pad :: Pad padLeft padTop padRight padBottom
4548
4649instance Show (Pad padLeft padTop padRight padBottom) where
src/Grenade/Layers/Pooling.hs+4−1
@@ -7,6 +7,8 @@
77{-# LANGUAGE TypeFamilies #-}
88{-# LANGUAGE MultiParamTypeClasses #-}
99{-# LANGUAGE FlexibleContexts #-}
10+{-# LANGUAGE NoStarIsType #-}
11+{-# LANGUAGE UndecidableInstances #-}
1012{-|
1113Module : Grenade.Core.Pooling
1214Description : Max Pooling layer for 2D and 3D images
@@ -28,6 +30,7 @@ import GHC.TypeLits hiding (natVal)
2830#else
2931import GHC.TypeLits
3032#endif
33+import Data.Kind (Type)
3134
3235import Grenade.Core
3336import Grenade.Layers.Internal.Pooling
@@ -42,7 +45,7 @@ import Numeric.LinearAlgebra.Static as LAS hiding ((|||), build, toRow
4245-- The kernel size dictates which input and output sizes will "fit". Fitting the equation:
4346-- `out = (in - kernel) / stride + 1` for both dimensions.
4447--
45−data Pooling :: Nat -> Nat -> Nat -> Nat -> * where
48+data Pooling :: Nat -> Nat -> Nat -> Nat -> Type where
4649 Pooling :: Pooling kernelRows kernelColumns strideRows strideColumns
4750
4851instance Show (Pooling k k' s s') where
src/Grenade/Layers/Reshape.hs+2
@@ -3,6 +3,8 @@
33{-# LANGUAGE TypeFamilies #-}
44{-# LANGUAGE MultiParamTypeClasses #-}
55{-# LANGUAGE FlexibleContexts #-}
6+{-# LANGUAGE NoStarIsType #-}
7+{-# LANGUAGE UndecidableInstances #-}
68{-|
79Module : Grenade.Layers.Reshape
810Description : Multipurpose reshaping layer
src/Grenade/Recurrent/Layers/ConcatRecurrent.hs+1
@@ -8,6 +8,7 @@
88{-# LANGUAGE FlexibleInstances #-}
99{-# LANGUAGE ScopedTypeVariables #-}
1010{-# LANGUAGE StandaloneDeriving #-}
11+{-# LANGUAGE UndecidableInstances #-}
1112{-|
1213Module : Grenade.Layers.Concat
1314Description : Concatenation layer