How to instance class with functional dependency?

Hi, In System.Posix.IOCtl, there is such a class: class Storable d => IOControl req d | req -> d where ioctlReqSource :: req -> CInt How to instance it? I do it as: data TIOCGWINSZ = TIOCGWINSZ #starttype struct winsize #field ws_row , CUShort #field ws_col , CUShort #field ws_xpixel , CUShort #field ws_ypixel , CUShort #stoptype instance IOControl TIOCGWINSZ C'winsize where ioctlReq _ = #const TIOCGWINSZ Then I got: topIO.hs:19:0: Couldn't match expected type `C'winsize' against inferred type `Int' When using functional dependencies to combine IOControl (Foreign.C.Types.CUShort -> Foreign.C.Types.CUShort -> Foreign.C.Types.CUShort -> Foreign.C.Types.CUShort -> C'winsize) Int, arising from a use of `ioctl'' at topIO.hs:21:35-60 IOControl (Foreign.C.Types.CUShort -> Foreign.C.Types.CUShort -> Foreign.C.Types.CUShort -> Foreign.C.Types.CUShort -> C'winsize) C'winsize, arising from a use of `ioctl'' at topIO.hs:20:12-37 When generalising the type(s) for `main' -- 竹密岂妨流水过 山高哪阻野云飞

Hi,
It sounds like your "use of `ioctl'' at topIO.hs:21:35-60" is passing
an "Int" as the 3rd argument to "ioctl", when your instance
declaration states that this argument should be a "C'winsize".
-Iavor
On Wed, Nov 24, 2010 at 11:27 PM, Magicloud Magiclouds
Hi, In System.Posix.IOCtl, there is such a class: class Storable d => IOControl req d | req -> d where ioctlReqSource :: req -> CInt How to instance it? I do it as: data TIOCGWINSZ = TIOCGWINSZ
#starttype struct winsize #field ws_row , CUShort #field ws_col , CUShort #field ws_xpixel , CUShort #field ws_ypixel , CUShort #stoptype
instance IOControl TIOCGWINSZ C'winsize where ioctlReq _ = #const TIOCGWINSZ
Then I got: topIO.hs:19:0: Couldn't match expected type `C'winsize' against inferred type `Int' When using functional dependencies to combine IOControl (Foreign.C.Types.CUShort -> Foreign.C.Types.CUShort -> Foreign.C.Types.CUShort -> Foreign.C.Types.CUShort -> C'winsize) Int, arising from a use of `ioctl'' at topIO.hs:21:35-60 IOControl (Foreign.C.Types.CUShort -> Foreign.C.Types.CUShort -> Foreign.C.Types.CUShort -> Foreign.C.Types.CUShort -> C'winsize) C'winsize, arising from a use of `ioctl'' at topIO.hs:20:12-37 When generalising the type(s) for `main' -- 竹密岂妨流水过 山高哪阻野云飞 _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (2)
-
Iavor Diatchki
-
Magicloud Magiclouds