
hi, i'm trying to get labelled records working with the current version of HList. i've got code that looks like:
{-# language EmptyDataDecls #-} module Tst where import Data.HList
data Foo; foo = proxy::Proxy Foo data Bar; bar = proxy::Proxy Bar rec1 = foo .=. 1 .*. bar .=. "hello" .*. emptyRecord
which gives me the error: Tst4.hs:8:2: No instance for (HEq (Proxy Foo) (Proxy Bar) HFalse) arising from a use of `.*.' at Tst4.hs:(8,2)-(10,12) Possible fix: add an instance declaration for (HEq (Proxy Foo) (Proxy Bar) HFalse) In the expression: foo .=. 1 .*. bar .=. "hello" .*. emptyRecord In the definition of `rec1': rec1 = foo .=. 1 .*. bar .=. "hello" .*. emptyRecord some discussion on #haskell suggesting importing Label4 and TypeEqGeneric1 but a) that's not possible because both are hidden inside the HList package and b) even when i get around that restriction, i still get a "No instance for (TypeCast HFalse HFalse)" error. thanks, rog.

It seems that a couple of modules in HList libraries didn't have enough LANGUAGE pragmas (in one case, GHC 6.8.3 started to require ScopedTypeVariables where the previous version of GHC did not). Cabal and OOHaskell supply all needed extensions on the command line, and so see no problems. I have corrected the pragmas, in http://darcs.haskell.org/HList You example indeed requires three more imports. In addition, if you import MakeLables and enable TemplateHaskell extension, you can define labels in a simpler way, for example $(label "varX") $(label "getX") The complete example follows. Also, the following file http://darcs.haskell.org/OOHaskell/OCamlTutorial.hs might possibly serve as a quite detailed example of extensible records. As the name of the file indicates, it is the OCaml Object tutorial (part of the OCaml documentation), only implemented in Haskell. {-# LANGUAGE EmptyDataDecls, TemplateHaskell #-} module Tst where import Data.HList import Data.HList.Label4 import Data.HList.TypeEqGeneric1 import Data.HList.TypeCastGeneric1 import Data.HList.MakeLabels data Foo; foo = proxy::Proxy Foo data Bar; bar = proxy::Proxy Bar rec1 = foo .=. 1 .*. bar .=. "hello" .*. emptyRecord -- Ralf likes this style rec2 = foo .=. 1 .*. bar .=. "hello" .*. emptyRecord t1 = rec2 # bar -- "hello" -- inferred foosel :: (HasField (Proxy Foo) r v) => r -> v foosel x = x # foo t2 = foosel rec1 -- 1 $(label "varX") $(label "getX") $(label "moveX") rec3 = varX .=. True .*. rec2 t4 = rec3 # varX -- True
participants (2)
-
oleg@okmij.org
-
roger peppe