1
0
Fork 0
mirror of https://github.com/tensorflow/haskell.git synced 2024-11-26 21:09:44 +01:00

Update type constraints to work around a ghc-8 bug. (#47)

Also removes all the ghc-8-specific logic in the .cabal files.

ghc-8 has issues with deeply nested tuples of constraints.  We can
work around it by:
- Changing TensorTypes to a regular class.  This required FlexibleContexts.
  (But we'll probably need it anyway when we support heterogeneous tensor
  lists.)
- Specializing NoneOf for long type lists.

For more details, see: https://ghc.haskell.org/trac/ghc/ticket/12175.

Also added 'directory' to tensorflow-core-ops' dependencies since it's used
in the Setup script.

One more step towards fixing #38.
This commit is contained in:
Judah Jacobson 2016-11-28 21:15:09 -08:00 committed by Greg Steuck
parent 71bdc6f744
commit 1539783ee5
9 changed files with 19 additions and 22 deletions

View file

@ -15,6 +15,7 @@ library
exposed-modules: TensorFlow.GenOps.Core exposed-modules: TensorFlow.GenOps.Core
build-depends: Cabal >= 1.22 && < 1.25 build-depends: Cabal >= 1.22 && < 1.25
, bytestring , bytestring
, directory
, proto-lens == 0.1.* , proto-lens == 0.1.*
, tensorflow-opgen == 0.1.* , tensorflow-opgen == 0.1.*
, tensorflow == 0.1.* , tensorflow == 0.1.*
@ -24,10 +25,6 @@ library
, lens-family , lens-family
, text , text
default-language: Haskell2010 default-language: Haskell2010
-- Work around https://ghc.haskell.org/trac/ghc/ticket/12175.
if impl(ghc >= 8) {
ghc-options: -fconstraint-solver-iterations=0
}
source-repository head source-repository head
type: git type: git

View file

@ -13,6 +13,7 @@
-- limitations under the License. -- limitations under the License.
{-# LANGUAGE DataKinds #-} {-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
module TensorFlow.NN module TensorFlow.NN

View file

@ -19,10 +19,6 @@ library
, tensorflow == 0.1.* , tensorflow == 0.1.*
, tensorflow-ops == 0.1.* , tensorflow-ops == 0.1.*
default-language: Haskell2010 default-language: Haskell2010
-- Work around https://ghc.haskell.org/trac/ghc/ticket/12175.
if impl(ghc >= 8) {
ghc-options: -fconstraint-solver-iterations=0
}
Test-Suite NNTest Test-Suite NNTest

View file

@ -117,6 +117,7 @@ docOpList :: OpGenFlags -> OpList -> Doc
docOpList flags opList = docOpList flags opList =
stack [ "{-# LANGUAGE ConstraintKinds #-}" stack [ "{-# LANGUAGE ConstraintKinds #-}"
, "{-# LANGUAGE DataKinds #-}" , "{-# LANGUAGE DataKinds #-}"
, "{-# LANGUAGE FlexibleContexts #-}"
, "{-# LANGUAGE FlexibleInstances #-}" , "{-# LANGUAGE FlexibleInstances #-}"
, "{-# LANGUAGE OverloadedStrings #-}" , "{-# LANGUAGE OverloadedStrings #-}"
, "{-# LANGUAGE ScopedTypeVariables #-}" , "{-# LANGUAGE ScopedTypeVariables #-}"

View file

@ -14,6 +14,7 @@
{-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-} {-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NoMonomorphismRestriction #-} {-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-} {-# LANGUAGE RankNTypes #-}

View file

@ -46,6 +46,7 @@
-- TensorFlow uses to avoid common subexpression elimination.) -- TensorFlow uses to avoid common subexpression elimination.)
{-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-} {-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedLists #-} {-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}

View file

@ -29,10 +29,6 @@ library
, tensorflow-core-ops == 0.1.* , tensorflow-core-ops == 0.1.*
, text , text
default-language: Haskell2010 default-language: Haskell2010
-- Work around https://ghc.haskell.org/trac/ghc/ticket/12175.
if impl(ghc >= 8) {
ghc-options: -fconstraint-solver-iterations=0
}
Test-Suite BuildTest Test-Suite BuildTest
default-language: Haskell2010 default-language: Haskell2010
@ -206,11 +202,6 @@ Test-Suite TypesTest
, test-framework-hunit , test-framework-hunit
, test-framework-quickcheck2 , test-framework-quickcheck2
, vector , vector
-- Work around https://ghc.haskell.org/trac/ghc/ticket/12175,
-- since this test defines its own ops.
if impl(ghc >= 8) {
ghc-options: -fconstraint-solver-iterations=0
}
Benchmark FeedFetchBench Benchmark FeedFetchBench
default-language: Haskell2010 default-language: Haskell2010

View file

@ -14,6 +14,7 @@
{-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-} {-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NoMonomorphismRestriction #-} {-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE OverloadedLists #-} {-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}

View file

@ -16,6 +16,7 @@
{-# LANGUAGE DataKinds #-} {-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-} {-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE ScopedTypeVariables #-}
@ -330,11 +331,11 @@ instance Attribute [Int64] where
type OneOf ts a type OneOf ts a
= (TensorType a, TensorTypes ts, NoneOf (AllTensorTypes \\ ts) a) = (TensorType a, TensorTypes ts, NoneOf (AllTensorTypes \\ ts) a)
-- | A 'Constraint' checking that the input is a list of 'TensorType's. -- | A check that the input is a list of 'TensorType's.
-- Helps improve error messages when using 'OneOf'. -- Helps improve error messages when using 'OneOf'.
type family TensorTypes ts :: Constraint where class TensorTypes (ts :: [*]) where
TensorTypes '[] = () instance TensorTypes '[]
TensorTypes (t ': ts) = (TensorType t, TensorTypes ts) instance (TensorType t, TensorTypes ts) => TensorTypes (t ': ts)
-- | A constraint checking that two types are different. -- | A constraint checking that two types are different.
type family a /= b :: Constraint where type family a /= b :: Constraint where
@ -378,5 +379,12 @@ type family as \\ bs where
-- | A constraint that the type @a@ doesn't appear in the type list @ts@. -- | A constraint that the type @a@ doesn't appear in the type list @ts@.
-- Assumes that @a@ and each of the elements of @ts@ are 'TensorType's. -- Assumes that @a@ and each of the elements of @ts@ are 'TensorType's.
type family NoneOf ts a :: Constraint where type family NoneOf ts a :: Constraint where
-- Specialize this type family when `ts` is a long list, to avoid deeply
-- nested tuples of constraints. Works around a bug in ghc-8:
-- https://ghc.haskell.org/trac/ghc/ticket/12175
NoneOf (t1 ': t2 ': t3 ': t4 ': ts) a
= (a /= t1, a /= t2, a /= t3, a /= t4, NoneOf ts a)
NoneOf (t1 ': t2 ': t3 ': ts) a = (a /= t1, a /= t2, a /= t3, NoneOf ts a)
NoneOf (t1 ': t2 ': ts) a = (a /= t1, a /= t2, NoneOf ts a)
NoneOf (t1 ': ts) a = (a /= t1, NoneOf ts a)
NoneOf '[] a = () NoneOf '[] a = ()
NoneOf (t ': ts) a = (a /= t, NoneOf ts a)