You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The lens generation example in the docs appears to be malformed. UserId seems to be used as a data constructor in the pattern match, but it is not one:
Prelude> :load Tutorial.hs
[1 of 1] Compiling Main ( Tutorial.hs, interpreted )
Tutorial.hs:39:10: error:
Not in scope: data constructor ‘UserId’
Perhaps you meant ‘User’ (line 8)
|
39 | (UserId (LensFor addressForUserId)) =
Where I have made a file called Tutorial.hs that pulls in the relevant lines from tutorials 1 and 2
Tutorial.hs
{-# LANGUAGE ImpredicativeTypes #-}
{-# LANGUAGE StandaloneDeriving #-}
import Database.Beam
import GHC.Int
import Data.Text (Text)
data UserT f
= User
{ _userEmail :: Columnar f Text
, _userFirstName :: Columnar f Text
, _userLastName :: Columnar f Text
, _userPassword :: Columnar f Text }
deriving Generic
type User = UserT Identity
type UserId = PrimaryKey UserT Identity
data AddressT f = Address
{ _addressId :: C f Int32
, _addressLine1 :: C f Text
, _addressLine2 :: C f (Maybe Text)
, _addressCity :: C f Text
, _addressState :: C f Text
, _addressZip :: C f Text
, _addressForUser :: PrimaryKey UserT f }
deriving (Generic, Beamable)
type Address = AddressT Identity
deriving instance Show (PrimaryKey UserT Identity)
deriving instance Show Address
instance Table AddressT where
data PrimaryKey AddressT f = AddressId (Columnar f Int32) deriving (Generic, Beamable)
primaryKey = AddressId . _addressId
type AddressId = PrimaryKey AddressT Identity -- For convenience
Address (LensFor addressId) (LensFor addressLine1)
(LensFor addressLine2) (LensFor addressCity)
(LensFor addressState) (LensFor addressZip)
(UserId (LensFor addressForUserId)) =
tableLenses
User (LensFor userEmail) (LensFor userFirstName)
(LensFor userLastName) (LensFor userPassword) =
tableLenses
The text was updated successfully, but these errors were encountered:
This looks like the same issue as in #659. I followed the example on the other issue and was able to generate lenses using micro lens, but got stuck trying to generate a lens for the foreign key between Address and User. This is the code I've got
addressId :: Lens Address Address Int32 Int32
addressLine1 :: Lens Address Address Text Text
addressLine2 :: Lens Address Address (Maybe Text) (Maybe Text)
addressCity :: Lens Address Address Text Text
addressState :: Lens Address Address Text Text
addressZip :: Lens Address Address Text Text
--addressForUser :: Lens Address Address ??? ???
Address (LensFor addressId) _ _ _ _ _ _ = tableLenses
Address _ (LensFor addressLine1) _ _ _ _ _ = tableLenses
Address _ _ (LensFor addressLine2) _ _ _ _ = tableLenses
Address _ _ _ (LensFor addressCity) _ _ _ = tableLenses
Address _ _ _ _ (LensFor addressState) _ _ = tableLenses
Address _ _ _ _ _ (LensFor addressZip) _ = tableLenses
-- Address _ _ _ _ _ _ (LensFor addressForUser) = tableLenses
userEmail :: Lens User User Text Text
userFirstName :: Lens User User Text Text
userLastName :: Lens User User Text Text
userPassword :: Lens User User Text Text
User (LensFor userEmail) _ _ _ = tableLenses
User _ (LensFor userFirstName) _ _ = tableLenses
User _ _ (LensFor userLastName) _ = tableLenses
User _ _ _ (LensFor userPassword) = tableLenses
I'm getting my head around Haskell, but does this mean that Beam cannot create lenses without using a library or templates with GHC>9.2 ?
The lens generation example in the docs appears to be malformed.
UserId
seems to be used as a data constructor in the pattern match, but it is not one:Where I have made a file called
Tutorial.hs
that pulls in the relevant lines from tutorials 1 and 2Tutorial.hs
The text was updated successfully, but these errors were encountered: