Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Replacing equals with equals not working (martin)
2. Re: Replacing equals with equals not working (Francesco Ariis)
3. Re: Replacing equals with equals not working (Henk-Jan van Tuyl)
4. Re: problem with SDL-gfx (Mart?n Villagra)
5. Re: Replacing equals with equals not working (martin)
----------------------------------------------------------------------
Message: 1
Date: Tue, 8 Dec 2015 23:29:22 +0100
From: martin <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Replacing equals with equals not working
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
Hello all,
with this code
import Data.List
import Data.Function
data Tree a = B a (Tree a) (Tree a) | L a Char deriving Show
get (B a _ _) = a
get (L a _) = a
tcmp = compare `on` get
build :: [Tree Int] -> [Tree Int]
build (t:[]) = [t]
-- build t = let xs = sortBy (compare `on` get) t -- < --
build t = let xs = sortBy tcmp t
in build (merge (xs!!0) (xs!!1) : drop 2 xs)
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?
The type variable ?b0? is ambiguous
Relevant bindings include
tcmp :: Tree b0 -> Tree b0 -> Ordering
(bound at
/home/martin/projects/haskell/exercises/99_questions/xxx.hs:10:1)
Note: there are several potential instances:
instance Integral a => Ord (GHC.Real.Ratio a)
-- Defined in ?GHC.Real?
instance Ord a => Ord (Control.Applicative.ZipList a)
-- Defined in ?Control.Applicative?
instance Ord Integer -- Defined in ?integer-gmp:GHC.Integer.Type?
...plus 24 others
In the first argument of ?on?, namely ?compare?
In the expression: compare `on` get
In an equation for ?tcmp?: tcmp = compare `on` get
Why is that so?
------------------------------
Message: 2
Date: Wed, 9 Dec 2015 01:03:32 +0100
From: Francesco Ariis <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Replacing equals with equals not
working
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
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?
------------------------------
Message: 3
Date: Wed, 09 Dec 2015 01:13:32 +0100
From: "Henk-Jan van Tuyl" <[email protected]>
To: [email protected], martin <[email protected]>
Subject: Re: [Haskell-beginners] Replacing equals with equals not
working
Message-ID: <op.x9cn37rtpz0j5l@alquantor>
Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes
On Tue, 08 Dec 2015 23:29:22 +0100, martin <[email protected]>
wrote:
:
> data Tree a = B a (Tree a) (Tree a) | L a Char deriving Show
>
> get (B a _ _) = a
> get (L a _) = a
>
> tcmp = compare `on` get
>
> build :: [Tree Int] -> [Tree Int]
> build (t:[]) = [t]
> -- build t = let xs = sortBy (compare `on` get) t -- < --
> build t = let xs = sortBy tcmp t
> in build (merge (xs!!0) (xs!!1) : drop 2 xs)
>
>
> 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?
> The type variable ?b0? is ambiguous
> Relevant bindings include
> tcmp :: Tree b0 -> Tree b0 -> Ordering
:
> Why is that so?
If you do not use the function tcmp, the compiler can not deduce the type
of it. When you add a type like
tcmp :: Ord a => Tree a -> Tree a -> Ordering
, the compiler has enough information to compile the program.
Regards,
Henk-Jan van Tuyl
--
Folding@home
What if you could share your unused computer power to help find a cure? In
just 5 minutes you can join the world's biggest networked computer and get
us closer sooner. Watch the video.
http://folding.stanford.edu/
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
Haskell programming
--
------------------------------
Message: 4
Date: Tue, 8 Dec 2015 21:21:39 -0300
From: Mart?n Villagra <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] problem with SDL-gfx
Message-ID:
<cae7wealgeaddb0gssy2wemafwevglntjt+sg_4ep7uwhwac...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Same error :/
The include folder (/usr/include/SDL/) contained the expected files.
(SDL_framerate.h and others)
I even recompiled and reinstalled the library but still says the same.
On Tue, Dec 8, 2015 at 3:58 PM, Francesco Ariis <[email protected]> wrote:
> On Tue, Dec 08, 2015 at 12:44:18PM -0300, Mart?n Villagra wrote:
> > Hello!
> > I hope you can help me. I'm trying to use SDL-gfx but it seems it isn't
> > linking it correctly. When I try to run this simple file with runhaskell:
> > import Graphics.UI.SDL.Primitives
> > main = putStrLn "Hello"
> >
> > It gives:
> > sdl.test.hs: <command line>: can't load .so/.DLL for:
> > [..]
>
> Hello Mart?n, SDL-gfx maintainer here. Could you try:
>
> runhaskell -L/usr/include/SDL/ -lSDL_gfx prova.hs
>
> (this works in Debian, modify the -L dir appropriately if you are using
> Arch).
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20151208/2353f2d1/attachment-0001.html>
------------------------------
Message: 5
Date: Wed, 9 Dec 2015 10:13:58 +0100
From: martin <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Replacing equals with equals not
working
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
Am 12/09/2015 um 01:03 AM schrieb Francesco Ariis:
> 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?
Oh, I see. I was assuming the message referred to the build function (because I
made chages there) and not to tcmp.
Didn't check the line number. But really tcmp has lost its roots by not being
used in build anymore.
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 90, Issue 14
*****************************************