[Haskell-cafe] How to instance class with functional dependency?

Magicloud Magiclouds magicloud.magiclouds at gmail.com
Thu Nov 25 08:27:05 CET 2010


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'
-- 
竹密岂妨流水过
山高哪阻野云飞


More information about the Haskell-Cafe mailing list