The instance is not exported?

I am trying to convert a tuple into HList.Record, and there is something really strange. I created a class ToRecordthat fastens a tuple of things and a tuple of labels for writing. Everything compiles, but the instances seem to disappear. When I try to use them, the GHC complains that the instance I am asking for does not exist.

{-# LANGUAGE TypeFamilies, DataKinds, TypeOperators #-}
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}

-- standard
import GHC.TypeLits (Symbol)
-- third-party
import Data.HList.FakePrelude
import Data.HList.Record
import Data.HList.Labelable
-- local

-- * Tuples <-> Records Conversion
class ToRecord a b where
    type Result a b :: *
    toRecord :: a -> b -> Result a b -- Result a b

instance  ToRecord (Label t1, Label t2) (v1, v2) where
    type Result (Label t1, Label t2) (v1, v2) = Record '[Tagged (t1) v1, Tagged (t2) v2]
    toRecord (t1, t2) (v1, v2) = t1 .=. v1 .*. t2 .=. v2 .*. emptyRecord

instance  ToRecord (Label t1, Label t2, Label t3) (v1, v2, v3) where
    type Result (Label t1, Label t2, Label t3) (v1, v2, v3) = 
         Record '[Tagged (t1) v1, Tagged (t2) v2, Tagged t3 v3]
    toRecord (t1, t2, t3) (v1, v2, v3) = t1 .=. v1 .*. t2 .=. v2 .*. t3 .=. v3 .*. emptyRecord

-- dummy instance to check GHC behavior
instance ToRecord Char Integer where
    type Result Char Integer = (Char, Integer)
    toRecord c i = (c, i)

value = Label :: Label "value"
name = Label :: Label "name"

test = toRecord  (value, name) (5 :: Int, "age")

Error message:

 Utils.hs:34:8:
 No instance for (ToRecord
                    (Label Symbol "value", Label Symbol "name") (Int, [Char]))
   arising from a use of `toRecord'
 Possible fix:
   add an instance declaration for
   (ToRecord
      (Label Symbol "value", Label Symbol "name") (Int, [Char]))
 In the expression: toRecord (value, name) (5 :: Int, "age")
 In an equation for `test':
    test = toRecord (value, name) (5 :: Int, "age")

Alternatively, if you delete the line testand upload the file to GHC. There are no instances (using :i ToRecord), only dummy appears ToRecod Char Integer.

Utils Database.Harehouse.SQLFragment>:i ToRecord
class ToRecord a b where
  type family Result a b :: *
  toRecord :: a -> b -> Result a b
        -- Defined at Database/Harehouse/Utils.hs:15:7
instance ToRecord Char Integer
  -- Defined at Database/Harehouse/Utils.hs:27:10

Any idea (I am using GHC 7.6.3)?

+4
source share
1 answer

: , ToRecord (Label Symbol "value", Label Symbol "name") (Int, [Char]), . , , : . ToRecord (Label (t1 :: *), Label (t2 :: *)) (v1, v2) - PolyKinds, *. :

l0 = Label :: Label Int
l1 = Label :: Label Bool

test = toRecord (l0, l1)  (5 :: Int, "age")

. PolyKinds,

instance ToRecord (Label (t1 :: k), Label (t2 :: k)) (v1, v2) where

:

>toRecord  (value, name) (5 :: Int, "age")
Record{value=5,name="age"}

, .

:

, , . , , , . Label : . kind - value :: Label Symbol "value" ( - ). , , GHC.

. *. t1 t2 ToRecord (Label t1, Label t2) (v1, v2) *. , Label ("value" :: Symbol) Label (t1 :: *) .

t1 :: k t1 :: Symbol , (f :: Integral a => a -> a) (1 :: Int) (f :: Int -> Int) (1 :: Int) . t1 :: Symbol KindSignatures, KindSignatures DataKinds PolyKinds.

+3
source

Source: https://habr.com/ru/post/1548188/


All Articles