[Haskell] [Haskell-cafe] Help with polymorphic functions

Wei Yuan Cai weiyuan.cai at gmail.com
Thu May 8 21:38:42 EDT 2008


Thank you all for the help. This was most helpful.

Regards,
Weiyuan


On Fri, May 9, 2008 at 8:16 AM, Brett G. Giles <brett.giles at ucalgary.ca>
wrote:

> Hi Wei
>
> Haskell needs to know that it can legally apply the function "shift".
> So, as requested, you need to add context to the typing of "test".
>
> if you define your function as:
>
> test :: (Data.Bits.Bits a) => a -> Int -> a
> test x n = shift x n
>
> you should be fine.
>
> On Fri, 2008-05-09 at 03:10 +0800, Wei Yuan Cai wrote:
> > Hello,
> >
> > I'm having some trouble with a polymorphic function using another
> > polymorphic function within. A simplified code of what I'm trying to
> > do is as follows:
> >
> > main = print $ test 1 8
> >
> > test :: a -> Int -> a
> > test x n = shift x n
> >
> > I get the following compilation error:
> >
> > Could not deduce (Data.Bits.Bits a) from the context ()
> >       arising from a use of `shift' at test.hs:8:11-19
> >     Possible fix:
> >       add (Data.Bits.Bits a) to the context of
> >         the type signature for `test'
> >     In the expression: shift x n
> >     In the definition of `test': test x n = shift x n
> >
> >
> > shift is defined as "a -> Int -> a"
> >
> > What am I doing wrong here?
> >
> > Thanks,
> > Weiyuan
> > _______________________________________________
> > Haskell mailing list
> > Haskell at haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell/attachments/20080509/aa673d72/attachment.htm


More information about the Haskell mailing list