
Hi
This is a very simple basic case, but I have a little trouble with this...
I hope somebody can help me
main :: IO()
main = return :: f
tipos :: Int -> Int -> Int -> Float
tipos a b c
f = b / a * c
where
(a,b,c) = (8,3,15)
Julita
On Thu, Nov 3, 2011 at 11:10 PM,
Send Haskell-Cafe mailing list submissions to haskell-cafe@haskell.org
To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/haskell-cafe or, via email, send a message with subject or body 'help' to haskell-cafe-request@haskell.org
You can reach the person managing the list at haskell-cafe-owner@haskell.org
When replying, please edit your Subject line so it is more specific than "Re: Contents of Haskell-Cafe digest..."
Today's Topics:
1. Re: How to speedup generically parsing sum types? (Jos? Pedro Magalh?es) 2. Re: How to speedup generically parsing sum types? (Bas van Dijk) 3. Re: The type class wilderness + Separating instances and implementations into separate packages (Ryan Newton) 4. Re: How to speedup generically parsing sum types? (Bas van Dijk) 5. Re: The type class wilderness + Separating instances and implementations into separate packages (Bas van Dijk) 6. Re: How to speedup generically parsing sum types? (Claus Reinke) 7. Re: How to speedup generically parsing sum types? (Bas van Dijk) 8. [ANNOUNCE] cereal-0.3.4.0 (Trevor Elliott) 9. System calls and Haskell threads (Andreas Voellmy) 10. Re: System calls and Haskell threads (Johan Tibell) 11. Is generic information dumpable? (Magicloud Magiclouds) 12. Re: Is generic information dumpable? (Jos? Pedro Magalh?es) 13. Re: How to speedup generically parsing sum types? (Twan van Laarhoven) 14. compiler construction (Timo von Holtz) 15. Re: System calls and Haskell threads (David Barbour) 16. Re: System calls and Haskell threads (David Barbour) 17. Re: How to speedup generically parsing sum types? (Bas van Dijk) 18. Re: compiler construction (Sean Leather) 19. Re: compiler construction (Thomas Schilling) 20. Mailing lists at haskell.org (Giovanni Tirloni) 21. Re: Mailing lists at haskell.org (Bas van Dijk) 22. Re: Is generic information dumpable? (Bas van Dijk) 23. Re: Is generic information dumpable? (Jos? Pedro Magalh?es) 24. Re: Is generic information dumpable? (Bas van Dijk) 25. Re: Message (Ryan Newton)
----------------------------------------------------------------------
Message: 1 Date: Thu, 3 Nov 2011 11:49:17 +0000 From: Jos? Pedro Magalh?es
Subject: Re: [Haskell-cafe] How to speedup generically parsing sum types? To: Bas van Dijk Cc: Haskell Cafe Message-ID: Content-Type: text/plain; charset="iso-8859-1"
Hi Bas,
First of all, thanks for these numbers. I have previously compared the performance of GP libs [1] and your results confirm what I would expect, except for that last one, BigSum/fromJSON/generic.
It's good that you're using INLINE pragmas on the generic function already. What I would also try: - Compile with -O2 and -fno-spec-constr-count (this last one is particularly important) - Add {-# INLINE [1] #-} pragmas to the to/from methods of your Generic instances.
To add these INLINE pragmas you will have to give your own instances of Generic (so you can't derive them). I'd suggest you get hold of them with -ddump-deriv, copy-paste and add the pragmas, just for testing purposes. The phase is important: you first want to make sure you inline the generic function definition, and only then the from/to.
Please keep me posted on the effects of these suggestions. In particular, if the INLINE pragmas on the from/to methods are essential, I'll be happy to add them to the derived instances.
Cheers, Pedro
[1] http://dreixel.net/research/pdf/ogie.pdf
2011/11/3 Bas van Dijk
Hello,
I recently added default generic implementations of toJSON and parseJSON to the aeson package. Now I'm optimizing them. Here are some benchmark results that compare:
* th: toJSON and fromJSON generated by template-haskell. Can be compared to hand-written code. Should be the fastest of all.
* syb: toJSON and fromJSON from the Data.Aeson.Generic module. Uses the Data type class.
* generic: my toJSON and fromJSON using GHC Generics.
The benchmark itself can be found here:
https://github.com/basvandijk/aeson/blob/optimizations/benchmarks/AesonCompa...
toJSON ======
D/toJSON/th 3.631734 us D/toJSON/syb 32.66679 us D/toJSON/generic 3.371868 us
BigRecord/toJSON/th 8.982990 us BigRecord/toJSON/syb 48.90737 us BigRecord/toJSON/generic 8.971597 us
BigProduct/toJSON/th 1.578259 us BigProduct/toJSON/syb 29.21153 us BigProduct/toJSON/generic 1.623115 us
BigSum/toJSON/th 51.81214 ns BigSum/toJSON/syb 1.256708 us BigSum/toJSON/generic 71.32851 ns
fromJSON ========
D/fromJSON/th 7.017204 us D/fromJSON/syb 23.46567 us D/fromJSON/generic 7.968974 us
BigRecord/fromJSON/th 8.513789 us BigRecord/fromJSON/syb 36.64501 us BigRecord/fromJSON/generic 10.07809 us
BigProduct/fromJSON/th 2.430677 us BigProduct/fromJSON/syb 17.97764 us BigProduct/fromJSON/generic 2.201130 us
BigSum/fromJSON/th 414.8699 ns BigSum/fromJSON/syb 4.113170 us BigSum/fromJSON/generic 13.62614 us !!!
As can be seen, in most cases the GHC Generics implementation is much faster than SYB and just as fast as TH. I'm impressed by how well GHC optimizes the code!
Unfortunately the last benchmark, generically parsing a big sum type, is much slower. The code for parsing sums, which can be found here:
https://github.com/basvandijk/aeson/blob/optimizations/Data/Aeson/Types/Inte...
is basically this:
instance (GFromSum a, GFromSum b) => GFromJSON (a :+: b) where gParseJSON (Object (M.toList -> [keyVal])) = gParseSum keyVal gParseJSON v = typeMismatch "sum (:+:)" v {-# INLINE gParseJSON #-}
class GFromSum f where gParseSum :: Pair -> Parser (f a)
instance (GFromSum a, GFromSum b) => GFromSum (a :+: b) where gParseSum keyVal = (L1 <$> gParseSum keyVal) <|> (R1 <$> gParseSum keyVal) {-# INLINE gParseSum #-}
instance (Constructor c, GFromJSON a, ConsFromJSON a) => GFromSum (C1 c a) where gParseSum (key, value) | key == pack (conName (undefined :: t c a p)) = gParseJSON value | otherwise = notFound $ unpack key {-# INLINE gParseSum #-}
notFound :: String -> Parser a notFound key = fail $ "The key \"" ++ key ++ "\" was not found" {-# INLINE notFound #-}
Any idea how to make it faster?
Regards,
Bas