[Haskell-beginners] Replacing equals with equals not working

Francesco Ariis fa-ml at ariis.it
Wed Dec 9 00:03:32 UTC 2015


On Tue, Dec 08, 2015 at 11:29:22PM +0100, martin wrote:
> Hello all,
> 
> with this code
> 
> [...]
> 
> The commented line -- < -- does not work, though I am just replacing equals
> with equals. I get
> 
>     No instance for (Ord b0) arising from a use of ‘compare’

Try to erase the `build` function and see what happens; You will get
the same error. GHC complains that there is no good `Ord` instance
and this can be solved by adding an appropriate type signature:

    tcmp :: (Ord a) => Tree a -> Tree a -> Ordering

Now, with the `build` function present (the one with
`let xs = sortBy tcmp t`), GHC will infer `tcmp` signature, as t is
an Int

    λ> :t tcmp
    tcmp :: Tree Int -> Tree Int -> Ordering

as since Int is an instance of Ord everything is fine.
Does that help?


More information about the Beginners mailing list