[Haskell-cafe] 123

Dmitriy Matrosov sgf.dma at gmail.com
Wed Aug 16 15:26:07 UTC 2017


Hi.

Is there a way to avoid `UndecidableInstances` in following code:

    data A f        = A {_a1 :: f String}

    instance Show (f String) => Show (A f) where

it does not compile with

    1.hs:4:10: error:
        • The constraint ‘Show (f String)’
            is no smaller than the instance head
          (Use UndecidableInstances to permit this)
        • In the instance declaration for ‘Show (A f)’

Though, initially, this was

    {-# LANGUAGE RankNTypes #-}

    data A f        = A {_a1 :: f String}

    instance forall f a. Show (f a) => Show (A f) where

which also does not compile with

    1.hs:5:10: error:
        • Variable ‘a’ occurs more often
            in the constraint ‘Show (f a)’ than in the instance head
          (Use UndecidableInstances to permit this)
        • In the instance declaration for ‘Show (A f)’

The error is different and i don't sure, that this two cases are related.

I want these instances to make a type with many records parametrized by
`Alternative` type, e.g.

    data Volume t       = Volume
                            { _volName  :: t Name
                            , _volSize  :: t Size
                            , _volPath  :: t Path
                            , _pool     :: t Pool
                            }

When i try to make instances, which require `*` type, i will end with
above cases.

--
  Dmitriy





More information about the Haskell-Cafe mailing list