Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/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. Re:  The cost of generality,      or how expensive is realToFrac?
      (Daniel Fischer)
   2.  Installing package hsc3 ? Haskell supercollider (Deb Midya)
   3. Re:  Installing package hsc3 ? Haskell supercollider
      (Brent Yorgey)
   4.  Re: How to delete a range from AVL tree.
      (Alexander.Vladislav.Popov )
   5. Re:  Re: How to delete a range from AVL tree. (Stephen Tetley)


----------------------------------------------------------------------

Message: 1
Date: Thu, 16 Sep 2010 23:33:53 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] The cost of generality,        or how
        expensive is realToFrac?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain;  charset="utf-8"

On Thursday 16 September 2010 21:47:43, Greg wrote:
> Wow, thanks for all the analysis on this, Daniel!
>
> So, I think the summary of your evaluation is that realToFrac does just
> fine in almost all cases

I wouldn't say that. realToFrac does fine in those cases where a rewrite 
rule provides a fast conversion (or one of the types bewteen which you want 
to convert is Rational, when you get fromRational or toRational - the 
latter can be improved in several cases).

> due to careful optimization and outperforms my
> floatToFloat trick (which answers the question I flagrantly begged...
> ;~) except that I can't access those optimizations because the OpenGL
> types are hidden behind newtypes and buried in a library.
>
> I've confirmed your results to make sure I could.
>
> I went a step further and typed convert for GLclampf expecting to see
> unoptimized performance, but it ran just as fast as Double->Float.
>
> convert :: Double -> GL.GLclampf
> convert = realToFrac

It would be interesting to see what core GHC produces for that (you can get 
the core with the `-ddump-simpl' command line flag [redirect stdout to a 
file] or with the ghc-core tool [available on hackage]).
If it runs as fast as realToFrac :: Double -> Float (with optimisations), 
GHC must have rewritten realToFrac to double2Float# and it should only do 
that if there are rewrite rules for GLclampf.
In that case, the problem is probably that GHC doesn't see the realToFrac 
applications because they're too deeply wrapped in your coordToCoord2D 
calls.

If that is the problem, it might help to use {-# INLINE #-} pragmas on 
coordToCoord2D, fromCartesian2D and toCartesian2D.
Can you try with realToFrac and the {-# INLINE #-} pragmas?

>
> And still ran faster than floatToFloat.  However there's no denying that
> floatToFloat runs *much* faster than realToFrac in the larger
> application.  Profiling shows floatToFloat taking about 50% of my CPU

That's too much for my liking, a simple conversion from Double to Float 
shouldn't take long, even if the Float is wrapped in newtypes (after all, 
the newtypes don't exist at runtime).

> time, but the frame rate is close to (though not quite) 30 fps.  Using
> realToFrac takes seconds just to display the first frame.
>
> As it stands, floatToFloat is responsible for 50% of my CPU time which I
> think is mainly a tribute the OpenGL implementation, but still makes it
> the obvious target for optimization.  Having gotten all excited about
> the new tool in my box, I wrote the following rule:
>
> {-# RULES
> "floatToFloat/id" floatToFloat=id
> "floatToFloat x2" floatToFloat . floatToFloat = floatToFloat
>  #-}
>
> Neither of which seems to fires in this application,

GHC reports fired rules with -ddump-simpl-stats.
Getting rules to fire is a little brittle, GHC does not try too hard to 
match expressions with rules, and if several rules match, it chooses one 
arbitrarily, so your rules may have been missed because the actual code 
looked different (perhaps because other rewrite rules fired first).

> but I did get the
> first one to fire by importing the same file into my benchmark.
>
> The next obvious step is to optimize a level up in the call hierarchy,
> and rewrite coordToCoord2D since I know my original pair2vertex function
> was faster.  So, I added this rule in the file where Vertex2 is made an
> instance of Coord2D:
>
> {-# RULES
> "coordToCoord2D/p2v2"  coordToCoord2D = pair2vertex
>  #-}
>
> which refers to two functions, each in different files (I don't think
> that matters, but mention it just in case)
>
> pair2vertex :: (Num a) => (a,a) -> GL.Vertex2 a
> pair2vertex (x,y) = GL.Vertex2 x y
>
> coordToCoord2D :: (Coord2D a, Coord2D b) => a -> b
> coordToCoord2D = fromCartesian2D . toCartesian2D
>
>
> directly after my coordToCoord2D definition I have this rule as well:
>
> {-# RULES
> "coordToCoord2D/id" coordToCoord2D = id
> "coordToCoord2D x2" coordToCoord2D . coordToCoord2D = coordToCoord2D
>  #-}
>
>
> I get a compile time error that I can't make sense of.  It's asking me
> to put a context on my rule, but I can't find any references on how to
> do that...
>
> -----------
>
>     Could not deduce (Num a)
>       from the context (Coord2D (Vertex2 a), Coord2D (a, a))
>       arising from a use of `pair2vertex'
>                    at GCB/OpenGL/Geometry.hs:32:40-50
>     Possible fix:
>       add (Num a) to the context of the RULE "coordToCoord2D/p2v2"
>     In the expression: pair2vertex
>     When checking the transformation rule "coordToCoord2D/p2v2"
>
>
> -----------
>
> The file:line:column is the "pair2vertex" token in the rule I list
> above.

Yes, there's a Num constraint on pair2vertex, but not on coordToCoord2D, so 
it's not type correct.
You could try removing the Num constraint from pair2vertex or add the 
constraint to the rule,

{-# RULES
"coordToCoord2D/p2v2" forall a. Num a =>  (coordToCoord2D :: (a,a) -> 
GL.Vertex2 a) = pair2vertex
   #-}

(well, I don't know whether that's the correct way, but you can try).

>
> Cheers--
>  Greg



------------------------------

Message: 2
Date: Thu, 16 Sep 2010 21:14:22 -0700 (PDT)
From: Deb Midya <[email protected]>
Subject: [Haskell-beginners] Installing package hsc3 ? Haskell
        supercollider
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"

Hi Haskell Users,
 
Thanks in advance.
 
I am using Haskell on Windows XP. I have downloaded 
HaskellPlatform-2010.2.0.0-setup.exe and installed it. I have checked that GHCi 
version is 6.12.3.
 
May I request you to assist me for the following please:
 
To install Haskell supercollider package, I have downloaded hsc3-0.7.tar.gz. 
How can I install this package now? Is there any document (how to use) on this 
package?
 
To assist me for this, I have also checked that whether cabal is working or 
not. To do that:
 
At dos prompt:
 
\ghc>cabal –help
 
\ghc> cabal install –help
 
It shows me flags for help and installation.
 
Once again, thank you very much for the time you have given.
 
Regards,
 
Deb
 


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100916/c62aca97/attachment-0001.html

------------------------------

Message: 3
Date: Fri, 17 Sep 2010 00:24:28 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Installing package hsc3 ? Haskell
        supercollider
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8

On Thu, Sep 16, 2010 at 09:14:22PM -0700, Deb Midya wrote:
> Hi Haskell Users,
>  
> Thanks in advance.
>  
> I am using Haskell on Windows XP. I have downloaded 
> HaskellPlatform-2010.2.0.0-setup.exe and installed it. I have checked that 
> GHCi version is 6.12.3.
>  
> May I request you to assist me for the following please:
>  
> To install Haskell supercollider package, I have downloaded hsc3-0.7.tar.gz. 
> How can I install this package now? Is there any document (how to use) on 
> this package?
>  
> To assist me for this, I have also checked that whether cabal is working or 
> not. To do that:
>  
> At dos prompt:
>  
> \ghc>cabal –help
>  
> \ghc> cabal install –help
>  
> It shows me flags for help and installation.

All you need to do is (at the DOS prompt)

  cabal install hsc3

and it will take care of downloading and installing all the
dependencies for you.

The latest version of hsc3 seems to be 0.8, is there a particular
reason you need 0.7?  If you specifically want 0.7 and not the latest
version you can specify that by instead doing

  cabal install hsc3-0.7

-Brent


------------------------------

Message: 4
Date: Fri, 17 Sep 2010 11:49:12 +0600
From: "Alexander.Vladislav.Popov "
        <[email protected]>
Subject: [Haskell-beginners] Re: How to delete a range from AVL tree.
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="utf-8"

Excuse me for the repost.
I'm sending it again because I have not find a reply from
[email protected] and I want to exclude (possible) problems
related to the mailing list.
I would be very much appritiated for any help or advice.

Alexander.

2010/9/16 Alexander.Vladislav.Popov <[email protected]>

> Hi.
>
> Help me to solve the problem I faced with.
> I'm trying to delete items from the AVL tree 'itree' that are between 0 and
> 2.
> But as you can see the result tree contains value of 1.
>
>
> > import Data.Tree.AVL
> > import Data.COrdering
>
> > mydelete' :: (Ord a) => a -> a -> AVL a -> AVL a
> > mydelete' p1 p2 tree = let res = delete cmp tree in
> >                        case contains res cmp of
> >                          True      -> mydelete' p1 p2 res
> >                          otherwise -> res
> >                        where
> >                          cmp  = between p1 p2
>
> > between a b x = if x < a
> >                 then LT
> >                 else if x > b
> >                      then GT
> >                      else EQ
>
>
> > itree = push ((sndByCC compare) 3) 3 (pair 1 2)
> > idel  = mydelete' 0 2
>
> *Main> idel itree
> P (Z E 1 E) 3 E
> *Main> idel $ idel itree
> P (Z E 1 E) 3 E
> *Main>
>
> Explain me why I got following results and where I made error.
>
> *Main> (mydelete' 0 3) itree
> E
> *Main> (mydelete' 0 2) itree
> P (Z E 1 E) 3 E
> *Main> (mydelete' 1 2) itree
> P (Z E 1 E) 3 E
> *Main> (mydelete' 1 1) itree
> Z (Z E 1 E) 2 (Z E 3 E)
> *Main> (mydelete' 2 1) itree
> Z (Z E 1 E) 2 (Z E 3 E)
> *Main> (mydelete' 0 1) itree
> Z (Z E 1 E) 2 (Z E 3 E)
> *Main> (mydelete' 0 2) itree
> P (Z E 1 E) 3 E
> *Main> (mydelete' (-1) 2) itree
> P (Z E 1 E) 3 E
>
> Alexander
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100917/7d088308/attachment-0001.html

------------------------------

Message: 5
Date: Fri, 17 Sep 2010 08:41:36 +0100
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] Re: How to delete a range from AVL
        tree.
To: "Alexander.Vladislav.Popov" <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Hello Alexander

I suspect mydelete' isn't working because it needs a "sorted" tree -
either the initial tree you are supplying isn't sorted or it becomes
unsorted after one delete step.

I don't know the AVL library at all (I only installed it now to look
at your problem) so I can't say from looking at the constructors
whether the problem tree is malformed, the problem tree being:

> P (Z E 1 E) 3 E

Potentially very few people use the Avl module which is why you
haven't had a reply yet. You could try posting to the Cafe instead if
you don't get a better answer.

Best wishes

Stephen


------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 27, Issue 40
*****************************************

Reply via email to