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

Iavor Diatchki iavor.diatchki at gmail.com
Fri Nov 26 17:35:56 CET 2010


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
<magicloud.magiclouds at gmail.com> wrote:
> 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list