HLint fails to give suggestions

I install HLint via cabal (output http://hpaste.org/88021) To check if it was working I used following code fun1 :: Int -> String fun1 1 = "hell" fun1 2 = 3 and ran HLint on it $ ~/.cabal/bin/hlint hlint_test.hs No suggestions and it ouputs no suggestions any ideas? Additionally $ ~/.cabal/bin/hlint -v HLint v1.8.45, (C) Neil Mitchell 2006-2012

Were you expecting a specific suggestion?
On Wed, May 15, 2013 at 11:04 AM, irfan hudda
I install HLint via cabal (output http://hpaste.org/88021) To check if it was working I used following code
fun1 :: Int -> String fun1 1 = "hell" fun1 2 = 3
and ran HLint on it $ ~/.cabal/bin/hlint hlint_test.hs No suggestions
and it ouputs no suggestions any ideas?
Additionally $ ~/.cabal/bin/hlint -v HLint v1.8.45, (C) Neil Mitchell 2006-2012
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Because the code
fun1 :: Int -> String
fun1 1 = "hell"
fun1 2 = 3
has obvious errors I was expecting HLint to display those errors.
On Wed, May 15, 2013 at 11:38 PM,
Send Beginners mailing list submissions to beginners@haskell.org
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 beginners-request@haskell.org
You can reach the person managing the list at beginners-owner@haskell.org
When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: Diagrams brain twister (Brent Yorgey) 2. Re: How to improve lazyness of a foldl (and memory footprint) (Brent Yorgey) 3. find by (Julian Arni) 4. find by (Julian Arni) 5. Re: find by (Brent Yorgey) 6. HLint fails to give suggestions (irfan hudda) 7. Re: HLint fails to give suggestions (Darren Grant)
----------------------------------------------------------------------
Message: 1 Date: Wed, 15 May 2013 12:21:50 -0400 From: Brent Yorgey
Subject: Re: [Haskell-beginners] Diagrams brain twister To: beginners@haskell.org Cc: diagrams-discuss@googlegroups.com Message-ID: <20130515162150.GA17348@seas.upenn.edu> Content-Type: text/plain; charset=us-ascii On Wed, May 15, 2013 at 11:06:28AM +0800, Adrian May wrote:
Hi all,
I'm trying to draw a picture with diagrams (this isn't the gantt chart I was talking about before.)
I have a load of objects strewn around a diagram according to their own sweet logic, and for *some* of them, I want to draw a horizontal line
from the right hand edge of the object to some globally fixed x coordinate, call it the "margin". So those lines are all different lengths because
objects are all over the place, but their right-hand ends should all be aligned vertically.
This seems quite hard, because that sweet logic is already quite complicated and local to a set of objects in the immediate neighbourhood of the object in question. Somehow I have to tease out a selection of them and process each of them into this line whose properties depend on where the object is from the global perspective.
Hi Adrian,
Actually, diagrams provides some tools specifically for accomplishing this kind of thing, so it is not that bad. (This question would probably be more appropriate on the diagrams mailing list---it has to do with the workings of diagrams in particular and not much to do with Haskell in general---so I'm also cc'ing that mailing list. Luckily I am subscribed to both. =)
The key is that you can give names to subparts of your diagram, combine them using whatever arbitrarily complicated logic you want, and then later learn some things about where they ended up in the overall diagram. Here is an example:
{-# LANGUAGE NoMonomorphismRestriction #-}
import Data.Maybe (fromMaybe) import Diagrams.Backend.SVG.CmdLine -- or Cairo, etc. import Diagrams.Prelude
-- We can "mark" things just by giving them the name () mark = named ()
-- A bunch of stuff, each positioned according to its own sweet logic, -- some of which are marked. Note, it's critical that we mark each -- subdiagram *after* any transformations which we want to affect how -- its "right edge" is determined (e.g. the scaleX on the circle -- below), but *before* any transformations which serve to position it -- in the overall diagram (e.g. the translations of the pentagon and -- square). stuff = ( triangle 3 # mark === circle 1 ) ||| ( pentagon 2 # mark # translateY 5 === circle 0.5 # scaleX 3 # mark ) ||| ( square 2 # mark # translateY 2 )
-- Draw horizontal lines extending from the right edges of any marked -- subdiagram to the given x-coordinate. Extract all the marked -- subdiagrams using 'withNameAll ()', turn each into a function to -- draw the required line, and apply all of them. drawLinesTo x = withNameAll () $ \subs -> applyAll (map drawLineFrom subs) where drawLineFrom sub = atop (edgePt ~~ xPoint) where -- Compute the point on the right edge of the subdiagram. This -- is a little ugly at the moment; I hope to add combinators -- to make this nicer. edgePt = fromMaybe origin (maxTraceP (location sub) unitX sub) -- Compute the other endpoint of the segment. y = snd (unp2 (location sub)) xPoint = p2 (x,y)
main = defaultMain (stuff # drawLinesTo 13 # centerXY # pad 1.1)
which produces this output:
http://www.cis.upenn.edu/~byorgey/hosted/Adrian.pdf
The code of this example is also available here: https://github.com/byorgey/diagrams-play/blob/master/Adrian.hs .
Hope this helps! If you have more questions feel free to ask on the diagrams mailing list or in the #diagrams IRC channel on freenode.
-Brent
------------------------------
Message: 2 Date: Wed, 15 May 2013 12:27:09 -0400 From: Brent Yorgey
Subject: Re: [Haskell-beginners] How to improve lazyness of a foldl (and memory footprint) To: beginners@haskell.org Message-ID: <20130515162709.GB17348@seas.upenn.edu> Content-Type: text/plain; charset=us-ascii For any associative binary operator (+) with an identity element z, foldl and foldr are equivalent, that is,
foldl (+) z === foldr (+) z
The first yields something like
((z + a) + b) + c
whereas the second yields
a + (b + (c + z))
but with associativity and the fact that z is an identity it is not hard to see that these are equal. However, as you found out, that does not necessarily mean they have the same performance!
Since atop is associative you could just replace foldl with foldr. In fact, atop is the binary operation for the Monoid instance of diagrams, so you can just write 'mconcat' in place of 'foldr atop mempty'.
-Brent
On Wed, May 15, 2013 at 09:35:34AM +0200, Giacomo Tesio wrote:
Thanks a lot!
Yesterday on freenode's #haskell channel Cane noted how my laziness
going the problem
reside in the foldl use in foldTradingSample. I have to turn it into a foldr (but I'm still unsure how...)
Giacomo
On Wed, May 15, 2013 at 12:46 AM, Henk-Jan van Tuyl
On Tue, 14 May 2013 11:22:27 +0200, Giacomo Tesio
wrote: Hi, I'm trying to improve a small haskell program of mine.
:
Some remarks:
0) Use hlint (available on Hackage) for improvement suggestions 1) You don't have to write the module heading in Main.hs, it is not a library (why export main?) 2) Change "print" to "putStrLn" if you want to display messages without quotes 2) switchArgs is only partially defined, add something like: switchArgs [x] = putStrLn $ "Unknown tool: " ++ x 3) Use shorter lines, for example change:
importTrades outDir csvFile = transformFile csvFile (foldTradingSample.* *getTickWriteTrades) (saveTradingSamples outDir)
to:
importTrades outDir csvFile = transformFile csvFile (foldTradingSample.**getTickWriteTrades) (saveTradingSamples outDir) 4) It is considered good practice, to write the function composition operator between spaces (change f.g to f . g)
I have analyze your software further to see how sufficient laziness can be reached.
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< http://members.chello.nl/hjgtuyl/tourdemonad.html> Haskell programming --
______________________________**_________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/**mailman/listinfo/beginners< http://www.haskell.org/mailman/listinfo/beginners>
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 3 Date: Wed, 15 May 2013 13:05:07 -0400 From: Julian Arni
Subject: [Haskell-beginners] find by To: Beginners@haskell.org Message-ID: Content-Type: text/plain; charset="iso-8859-1" (For some reason my previous post seems to have been truncated.)
I have a function that, simplifying a little, looks like this:
fn :: [a] -> a fn = (head .) . takeWhile $ (\_ -> True)
From this, I want a function with the signature fn' :: [(x,a)] -> (x,a) such that:
snd $ fn' (zip [x] [a]) = fn [a]
I can see ways of doing this by altering fn, or by repeating some of fn in the definition of fn', or (because in this case I know that if fn xs = x, fn is returning the first x in xs and not any others), by doing something nasty like:
fn' xs = xs !! fromMaybe 0 (findIndex (\(_,a) -> a == fn (snd $ unzip xs)) xs )
But it seems to me like there should be prettier solutions to this (that *do not* involve changing the definition of fn). After all, this doesn't seem like a rare pattern.
Anyone know if in fact there's a better way to go about it?

irfan hudda wrote:
Because the code fun1 :: Int -> String fun1 1 = "hell" fun1 2 = 3 has obvious errors I was expecting HLint to display those errors.
The compiler show errors, hlint provides coding style suggestions. Two different tools for two different jobs. I usually only run hlint on code after I am sure it compiles. Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 15/05/13 19:21, irfan hudda wrote:
Because the code fun1 :: Int -> String fun1 1 = "hell" fun1 2 = 3 has obvious errors I was expecting HLint to display those errors.
I think you don't understand what HLint is supposed to do. It's GHC's job to show you type errors. HLint is only there to give you suggestions about style. I believe that the most it can do in terms of errors is to throw a fit when you have invalid syntax (not the case here). Example usage:
module Test where
main :: IO () main = print $ show $ id $ id $ id 5
I get
Test.hs:5:23: Error: Evaluate Found: id $ id $ id 5 Why not: (id $ id 5)
Test.hs:5:28: Error: Evaluate Found: id $ id 5 Why not: id 5
Test.hs:5:33: Error: Evaluate Found: id 5 Why not: 5
3 suggestions
- -- Mateusz K. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) iQIcBAEBAgAGBQJRk9OIAAoJEM1mucMq2pqXhb4P/RqzmJHCHWw3PDHg9Q/KmRKs 0I0xKF+u3mEkOt3xzGg9LO+aqueLCIiSDWItY6romGJNJBI4pz5DA7uc5LOrJASm z+K2LwC3E7laoW58S9xWgU6hJiGb2HkaVunC78d79mnOPJYq5rpDKzYMTjZssGwM AAE4C7VZQv6Bbx8iPa/Q5E6Sh1cCLSrHWqmznjCaIpO1TuKJd7+i10Jq6y6kBgDE VDl/UE6TUGs2ZQCAtLSxwflKloeyNyFf/GCCl35iceAp4uWBwHnuzwLWHEL6TRsq nT6R3O3vQ8woVOh7S8cEfNutHbSreFRAdZOZDLA5G8rXqDLTLe0Rj+UyW8ckORdR 78Xlf6ZKENWB+TT9/LNKtY1mFy0A2biarQcgwslq5pCf0LX/+IJl2EL56hefABrr PHxb6llg4n9S0Har2Cqgv3xBfI81m4gdiqsTaiwzs+BA9p9h42nSlea83aShGkKm PFVYAZkeGsFhEuBk33mlivp7SchOd3Or/xNUtexNWREMtDb+C5mDH9qttIPwdJKU rKmIYPC5BfQJxcFytII6iM2QNDgFZQ9LsfrItbMfW0nWPf6tx+Xu2gtPka5MXJTj ispXg39L9De/EZP+71R+n8KqWCHp/5lMq0LQ92lmoXp1soDWZh52b2CjivoYG6PS /PUjOX6FEfJKzWz4OGhQ =xgst -----END PGP SIGNATURE-----

Ah you're right. :) A full or type-checking build catches that, but HLint
does not.
I'm curious about this too; does HLint not need code that checks out in the
type system?
Cheers,
Darren
On Wed, May 15, 2013 at 11:21 AM, irfan hudda
Because the code
fun1 :: Int -> String fun1 1 = "hell" fun1 2 = 3 has obvious errors I was expecting HLint to display those errors.
On Wed, May 15, 2013 at 11:38 PM,
wrote: Send Beginners mailing list submissions to beginners@haskell.org
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 beginners-request@haskell.org
You can reach the person managing the list at beginners-owner@haskell.org
When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: Diagrams brain twister (Brent Yorgey) 2. Re: How to improve lazyness of a foldl (and memory footprint) (Brent Yorgey) 3. find by (Julian Arni) 4. find by (Julian Arni) 5. Re: find by (Brent Yorgey) 6. HLint fails to give suggestions (irfan hudda) 7. Re: HLint fails to give suggestions (Darren Grant)
----------------------------------------------------------------------
Message: 1 Date: Wed, 15 May 2013 12:21:50 -0400 From: Brent Yorgey
Subject: Re: [Haskell-beginners] Diagrams brain twister To: beginners@haskell.org Cc: diagrams-discuss@googlegroups.com Message-ID: <20130515162150.GA17348@seas.upenn.edu> Content-Type: text/plain; charset=us-ascii On Wed, May 15, 2013 at 11:06:28AM +0800, Adrian May wrote:
Hi all,
I'm trying to draw a picture with diagrams (this isn't the gantt chart
was talking about before.)
I have a load of objects strewn around a diagram according to their own sweet logic, and for *some* of them, I want to draw a horizontal line going from the right hand edge of the object to some globally fixed x coordinate, call it the "margin". So those lines are all different lengths because
objects are all over the place, but their right-hand ends should all be aligned vertically.
This seems quite hard, because that sweet logic is already quite complicated and local to a set of objects in the immediate neighbourhood of the object in question. Somehow I have to tease out a selection of
process each of them into this line whose properties depend on where
object is from the global perspective.
Hi Adrian,
Actually, diagrams provides some tools specifically for accomplishing this kind of thing, so it is not that bad. (This question would probably be more appropriate on the diagrams mailing list---it has to do with the workings of diagrams in particular and not much to do with Haskell in general---so I'm also cc'ing that mailing list. Luckily I am subscribed to both. =)
The key is that you can give names to subparts of your diagram, combine them using whatever arbitrarily complicated logic you want, and then later learn some things about where they ended up in the overall diagram. Here is an example:
{-# LANGUAGE NoMonomorphismRestriction #-}
import Data.Maybe (fromMaybe) import Diagrams.Backend.SVG.CmdLine -- or Cairo, etc. import Diagrams.Prelude
-- We can "mark" things just by giving them the name () mark = named ()
-- A bunch of stuff, each positioned according to its own sweet logic, -- some of which are marked. Note, it's critical that we mark each -- subdiagram *after* any transformations which we want to affect how -- its "right edge" is determined (e.g. the scaleX on the circle -- below), but *before* any transformations which serve to position it -- in the overall diagram (e.g. the translations of the pentagon and -- square). stuff = ( triangle 3 # mark === circle 1 ) ||| ( pentagon 2 # mark # translateY 5 === circle 0.5 # scaleX 3 # mark ) ||| ( square 2 # mark # translateY 2 )
-- Draw horizontal lines extending from the right edges of any marked -- subdiagram to the given x-coordinate. Extract all the marked -- subdiagrams using 'withNameAll ()', turn each into a function to -- draw the required line, and apply all of them. drawLinesTo x = withNameAll () $ \subs -> applyAll (map drawLineFrom subs) where drawLineFrom sub = atop (edgePt ~~ xPoint) where -- Compute the point on the right edge of the subdiagram. This -- is a little ugly at the moment; I hope to add combinators -- to make this nicer. edgePt = fromMaybe origin (maxTraceP (location sub) unitX sub) -- Compute the other endpoint of the segment. y = snd (unp2 (location sub)) xPoint = p2 (x,y)
main = defaultMain (stuff # drawLinesTo 13 # centerXY # pad 1.1)
which produces this output:
http://www.cis.upenn.edu/~byorgey/hosted/Adrian.pdf
The code of this example is also available here: https://github.com/byorgey/diagrams-play/blob/master/Adrian.hs .
Hope this helps! If you have more questions feel free to ask on the diagrams mailing list or in the #diagrams IRC channel on freenode.
-Brent
------------------------------
Message: 2 Date: Wed, 15 May 2013 12:27:09 -0400 From: Brent Yorgey
Subject: Re: [Haskell-beginners] How to improve lazyness of a foldl (and memory footprint) To: beginners@haskell.org Message-ID: <20130515162709.GB17348@seas.upenn.edu> Content-Type: text/plain; charset=us-ascii For any associative binary operator (+) with an identity element z, foldl and foldr are equivalent, that is,
foldl (+) z === foldr (+) z
The first yields something like
((z + a) + b) + c
whereas the second yields
a + (b + (c + z))
but with associativity and the fact that z is an identity it is not hard to see that these are equal. However, as you found out, that does not necessarily mean they have the same performance!
Since atop is associative you could just replace foldl with foldr. In fact, atop is the binary operation for the Monoid instance of diagrams, so you can just write 'mconcat' in place of 'foldr atop mempty'.
-Brent
On Wed, May 15, 2013 at 09:35:34AM +0200, Giacomo Tesio wrote:
Thanks a lot!
Yesterday on freenode's #haskell channel Cane noted how my laziness
I the them and the problem
reside in the foldl use in foldTradingSample. I have to turn it into a foldr (but I'm still unsure how...)
Giacomo
On Wed, May 15, 2013 at 12:46 AM, Henk-Jan van Tuyl
On Tue, 14 May 2013 11:22:27 +0200, Giacomo Tesio
wrote: Hi, I'm trying to improve a small haskell program of mine.
:
Some remarks:
0) Use hlint (available on Hackage) for improvement suggestions 1) You don't have to write the module heading in Main.hs, it is not a library (why export main?) 2) Change "print" to "putStrLn" if you want to display messages without quotes 2) switchArgs is only partially defined, add something like: switchArgs [x] = putStrLn $ "Unknown tool: " ++ x 3) Use shorter lines, for example change:
importTrades outDir csvFile = transformFile csvFile (foldTradingSample.* *getTickWriteTrades) (saveTradingSamples outDir)
to:
importTrades outDir csvFile = transformFile csvFile (foldTradingSample.**getTickWriteTrades) (saveTradingSamples outDir) 4) It is considered good practice, to write the function composition operator between spaces (change f.g to f . g)
I have analyze your software further to see how sufficient laziness can be reached.
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< http://members.chello.nl/hjgtuyl/tourdemonad.html> Haskell programming --
______________________________**_________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/**mailman/listinfo/beginners< http://www.haskell.org/mailman/listinfo/beginners>
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 3 Date: Wed, 15 May 2013 13:05:07 -0400 From: Julian Arni
Subject: [Haskell-beginners] find by To: Beginners@haskell.org Message-ID: Content-Type: text/plain; charset="iso-8859-1" (For some reason my previous post seems to have been truncated.)
I have a function that, simplifying a little, looks like this:
fn :: [a] -> a fn = (head .) . takeWhile $ (\_ -> True)
From this, I want a function with the signature fn' :: [(x,a)] -> (x,a) such that:
snd $ fn' (zip [x] [a]) = fn [a]
I can see ways of doing this by altering fn, or by repeating some of fn in the definition of fn', or (because in this case I know that if fn xs = x, fn is returning the first x in xs and not any others), by doing something nasty like:
fn' xs = xs !! fromMaybe 0 (findIndex (\(_,a) -> a == fn (snd $ unzip xs)) xs )
But it seems to me like there should be prettier solutions to this (that *do not* involve changing the definition of fn). After all, this doesn't seem like a rare pattern.
Anyone know if in fact there's a better way to go about it?

Nope, it doesn't. HLint uses haskell-src-exts to parse code, but it does no typechecking. So HLint will be perfectly happy with anything that is valid Haskell syntax, whether it typechecks or not. -Brent On Wed, May 15, 2013 at 11:42:39AM -0700, Darren Grant wrote:
Ah you're right. :) A full or type-checking build catches that, but HLint does not.
I'm curious about this too; does HLint not need code that checks out in the type system?
Cheers, Darren
On Wed, May 15, 2013 at 11:21 AM, irfan hudda
wrote: Because the code
fun1 :: Int -> String fun1 1 = "hell" fun1 2 = 3 has obvious errors I was expecting HLint to display those errors.
On Wed, May 15, 2013 at 11:38 PM,
wrote: Send Beginners mailing list submissions to beginners@haskell.org
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 beginners-request@haskell.org
You can reach the person managing the list at beginners-owner@haskell.org
When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: Diagrams brain twister (Brent Yorgey) 2. Re: How to improve lazyness of a foldl (and memory footprint) (Brent Yorgey) 3. find by (Julian Arni) 4. find by (Julian Arni) 5. Re: find by (Brent Yorgey) 6. HLint fails to give suggestions (irfan hudda) 7. Re: HLint fails to give suggestions (Darren Grant)
----------------------------------------------------------------------
Message: 1 Date: Wed, 15 May 2013 12:21:50 -0400 From: Brent Yorgey
Subject: Re: [Haskell-beginners] Diagrams brain twister To: beginners@haskell.org Cc: diagrams-discuss@googlegroups.com Message-ID: <20130515162150.GA17348@seas.upenn.edu> Content-Type: text/plain; charset=us-ascii On Wed, May 15, 2013 at 11:06:28AM +0800, Adrian May wrote:
Hi all,
I'm trying to draw a picture with diagrams (this isn't the gantt chart
was talking about before.)
I have a load of objects strewn around a diagram according to their own sweet logic, and for *some* of them, I want to draw a horizontal line going from the right hand edge of the object to some globally fixed x coordinate, call it the "margin". So those lines are all different lengths because
objects are all over the place, but their right-hand ends should all be aligned vertically.
This seems quite hard, because that sweet logic is already quite complicated and local to a set of objects in the immediate neighbourhood of the object in question. Somehow I have to tease out a selection of
process each of them into this line whose properties depend on where
object is from the global perspective.
Hi Adrian,
Actually, diagrams provides some tools specifically for accomplishing this kind of thing, so it is not that bad. (This question would probably be more appropriate on the diagrams mailing list---it has to do with the workings of diagrams in particular and not much to do with Haskell in general---so I'm also cc'ing that mailing list. Luckily I am subscribed to both. =)
The key is that you can give names to subparts of your diagram, combine them using whatever arbitrarily complicated logic you want, and then later learn some things about where they ended up in the overall diagram. Here is an example:
{-# LANGUAGE NoMonomorphismRestriction #-}
import Data.Maybe (fromMaybe) import Diagrams.Backend.SVG.CmdLine -- or Cairo, etc. import Diagrams.Prelude
-- We can "mark" things just by giving them the name () mark = named ()
-- A bunch of stuff, each positioned according to its own sweet logic, -- some of which are marked. Note, it's critical that we mark each -- subdiagram *after* any transformations which we want to affect how -- its "right edge" is determined (e.g. the scaleX on the circle -- below), but *before* any transformations which serve to position it -- in the overall diagram (e.g. the translations of the pentagon and -- square). stuff = ( triangle 3 # mark === circle 1 ) ||| ( pentagon 2 # mark # translateY 5 === circle 0.5 # scaleX 3 # mark ) ||| ( square 2 # mark # translateY 2 )
-- Draw horizontal lines extending from the right edges of any marked -- subdiagram to the given x-coordinate. Extract all the marked -- subdiagrams using 'withNameAll ()', turn each into a function to -- draw the required line, and apply all of them. drawLinesTo x = withNameAll () $ \subs -> applyAll (map drawLineFrom subs) where drawLineFrom sub = atop (edgePt ~~ xPoint) where -- Compute the point on the right edge of the subdiagram. This -- is a little ugly at the moment; I hope to add combinators -- to make this nicer. edgePt = fromMaybe origin (maxTraceP (location sub) unitX sub) -- Compute the other endpoint of the segment. y = snd (unp2 (location sub)) xPoint = p2 (x,y)
main = defaultMain (stuff # drawLinesTo 13 # centerXY # pad 1.1)
which produces this output:
http://www.cis.upenn.edu/~byorgey/hosted/Adrian.pdf
The code of this example is also available here: https://github.com/byorgey/diagrams-play/blob/master/Adrian.hs .
Hope this helps! If you have more questions feel free to ask on the diagrams mailing list or in the #diagrams IRC channel on freenode.
-Brent
------------------------------
Message: 2 Date: Wed, 15 May 2013 12:27:09 -0400 From: Brent Yorgey
Subject: Re: [Haskell-beginners] How to improve lazyness of a foldl (and memory footprint) To: beginners@haskell.org Message-ID: <20130515162709.GB17348@seas.upenn.edu> Content-Type: text/plain; charset=us-ascii For any associative binary operator (+) with an identity element z, foldl and foldr are equivalent, that is,
foldl (+) z === foldr (+) z
The first yields something like
((z + a) + b) + c
whereas the second yields
a + (b + (c + z))
but with associativity and the fact that z is an identity it is not hard to see that these are equal. However, as you found out, that does not necessarily mean they have the same performance!
Since atop is associative you could just replace foldl with foldr. In fact, atop is the binary operation for the Monoid instance of diagrams, so you can just write 'mconcat' in place of 'foldr atop mempty'.
-Brent
On Wed, May 15, 2013 at 09:35:34AM +0200, Giacomo Tesio wrote:
Thanks a lot!
Yesterday on freenode's #haskell channel Cane noted how my laziness
I the them and the problem
reside in the foldl use in foldTradingSample. I have to turn it into a foldr (but I'm still unsure how...)
Giacomo
On Wed, May 15, 2013 at 12:46 AM, Henk-Jan van Tuyl
On Tue, 14 May 2013 11:22:27 +0200, Giacomo Tesio
wrote: Hi, I'm trying to improve a small haskell program of mine.
:
Some remarks:
0) Use hlint (available on Hackage) for improvement suggestions 1) You don't have to write the module heading in Main.hs, it is not a library (why export main?) 2) Change "print" to "putStrLn" if you want to display messages without quotes 2) switchArgs is only partially defined, add something like: switchArgs [x] = putStrLn $ "Unknown tool: " ++ x 3) Use shorter lines, for example change:
importTrades outDir csvFile = transformFile csvFile (foldTradingSample.* *getTickWriteTrades) (saveTradingSamples outDir)
to:
importTrades outDir csvFile = transformFile csvFile (foldTradingSample.**getTickWriteTrades) (saveTradingSamples outDir) 4) It is considered good practice, to write the function composition operator between spaces (change f.g to f . g)
I have analyze your software further to see how sufficient laziness can be reached.
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< http://members.chello.nl/hjgtuyl/tourdemonad.html> Haskell programming --
______________________________**_________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/**mailman/listinfo/beginners< http://www.haskell.org/mailman/listinfo/beginners>
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 3 Date: Wed, 15 May 2013 13:05:07 -0400 From: Julian Arni
Subject: [Haskell-beginners] find by To: Beginners@haskell.org Message-ID: Content-Type: text/plain; charset="iso-8859-1" (For some reason my previous post seems to have been truncated.)
I have a function that, simplifying a little, looks like this:
fn :: [a] -> a fn = (head .) . takeWhile $ (\_ -> True)
From this, I want a function with the signature fn' :: [(x,a)] -> (x,a) such that:
snd $ fn' (zip [x] [a]) = fn [a]
I can see ways of doing this by altering fn, or by repeating some of fn in the definition of fn', or (because in this case I know that if fn xs = x, fn is returning the first x in xs and not any others), by doing something nasty like:
fn' xs = xs !! fromMaybe 0 (findIndex (\(_,a) -> a == fn (snd $ unzip xs)) xs )
But it seems to me like there should be prettier solutions to this (that *do not* involve changing the definition of fn). After all, this doesn't seem like a rare pattern.
Anyone know if in fact there's a better way to go about it?

Hlint doesn't compile your code. It only looks for common patterns in
code that are usually bad. It is going on the assumption that your
code already compiled and you are just looking for some advice on
refactoring.
234234 = do
return 1
gives
Blah5.hs:2:10: Error: Redundant do
Found:
do return 1
Why not:
return 1
On Wed, May 15, 2013 at 2:04 PM, irfan hudda
I install HLint via cabal (output http://hpaste.org/88021) To check if it was working I used following code
fun1 :: Int -> String fun1 1 = "hell" fun1 2 = 3
and ran HLint on it $ ~/.cabal/bin/hlint hlint_test.hs No suggestions
and it ouputs no suggestions any ideas?
Additionally $ ~/.cabal/bin/hlint -v HLint v1.8.45, (C) Neil Mitchell 2006-2012
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

David answered my question.
On Wed, May 15, 2013 at 11:27 AM, David McBride
Hlint doesn't compile your code. It only looks for common patterns in code that are usually bad. It is going on the assumption that your code already compiled and you are just looking for some advice on refactoring.
234234 = do return 1
gives
Blah5.hs:2:10: Error: Redundant do Found: do return 1 Why not: return 1
On Wed, May 15, 2013 at 2:04 PM, irfan hudda
wrote: I install HLint via cabal (output http://hpaste.org/88021) To check if it was working I used following code
fun1 :: Int -> String fun1 1 = "hell" fun1 2 = 3
and ran HLint on it $ ~/.cabal/bin/hlint hlint_test.hs No suggestions
and it ouputs no suggestions any ideas?
Additionally $ ~/.cabal/bin/hlint -v HLint v1.8.45, (C) Neil Mitchell 2006-2012
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
participants (6)
-
Brent Yorgey
-
Darren Grant
-
David McBride
-
Erik de Castro Lopo
-
irfan hudda
-
Mateusz Kowalczyk