Re: [Haskell-cafe] Alternative name for return

2013-08-06 Thread Lyndon Maydwell
What about "promote" ?


On Tue, Aug 6, 2013 at 6:15 PM, Tom Ellis <
tom-lists-haskell-cafe-2...@jaguarpaw.co.uk> wrote:

> On Tue, Aug 06, 2013 at 10:03:04AM +0200, J. Stutterheim wrote:
> > `putStrLn "Hi"` is not a pure value...
>
> Why not?
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Problem with pipes interpretation of Lazy MapM program.

2013-07-11 Thread Lyndon Maydwell
Hi café.

I've come up with a little version of 'uniq' that should take into account
md5 sums of the file changes... In essence, this:


main :: IO ()
main = getContents
   >>= mapM check . lines -- PROBLEM
   >>= mapM_ (putStrLn . (" --> " ++ )) . strip

check :: String -> IO (String, ABCD)
check s = (s,) . md5 . Str <$> readFile s

strip :: (Ord a, Eq b) => [(a,b)] -> [a]
strip = concat . uncurry (zipWith look) . (id &&& maps)

look :: (Ord a, Eq b) => (a,b) -> M.Map a b -> [a]
look (k,v) m | M.lookup k m == Just v = []
 | otherwise  = [k]

maps :: Ord a => [(a,b)] -> [M.Map a b]
maps = scanl (flip (uncurry M.insert)) M.empty


Unfortunately mapM isn't lazy, so this doesn't work. I thought this would
be a good opportunity to try out the Pipes library for a simple real-world
task, but I've come up against some issues with using 'zip' and 'scan' like
functions when translating the code.

This is what I've got so far, but I'm not sure how to proceed:


main :: IO ()
main = runProxy $ stdinS >-> pipe >-> stdoutD

pipe :: () -> ProxyFast () String () String IO ()
pipe = mapMD check
   >-> mapScan
  -- zip, check, output go here
   >-> mapD ((" --> " ++) . show)

mapScan :: () -> ProxyFast () (String, ABCD) () (M.Map String ABCD) IO b
mapScan = scanlp (uncurry M.insert) (M.empty)

check :: String -> IO (String, ABCD)
check s = (s,) . md5 . Str <$> readFile s

-- Utils

scanlp :: (Monad (p () t a b1 m), Monad m, Functor (p () t a b1 m), Proxy
p) =>
  (t -> b1 -> b1) -> b1 -> () -> p () t a b1 m b
scanlp f a b = do
  void $ respond a
  v <- request ()
  scanlp f (f v a) b


There doesn't seem to be any easy zipLike functions, and having to write my
own scan function seems odd. Can someone point me in the right direction
for this?


Thanks!

 - Lyndon
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Product-Categories

2013-07-04 Thread Lyndon Maydwell
Thanks a lot for that Adam.

Glad to hear I wasn't too far off the right track :-)


Regards,

 - Lyndon


On Thu, Jul 4, 2013 at 5:34 PM, Adam Gundry wrote:

> Hi,
>
> On 04/07/13 02:19, Lyndon Maydwell wrote:
> > I'm wracking my brain trying to figure out a simple, reasonably general,
> > implementation for a category instance for pairs of categories.
> >
> > So far I've looked at [1], which seems great, but doesn't use the
> > built-in category instance, and [2], which I'm just not sure about.
>
> Unless I misunderstand your question, I think [1] is the way to achieve
> what you want (indeed the blog post mentions defining a Category
> instance for product categories). It uses the same Category class as in
> base, but with the PolyKinds extension turned on, which is necessary if
> you want objects of the category to be anything other than types of kind
> *, as the post explains. This generalisation should be in the next
> release of base [3].
>
> It looks like [2] is defining Cartesian categories, which have an
> internal product, rather than taking the product of categories. If only
> we could make a category of categories...
>
> Back to your question, consider the following:
>
>
> {-# LANGUAGE TypeFamilies, TypeOperators, PolyKinds, DataKinds #-}
>
> module ProductCategory where
>
> import Prelude hiding (id, (.))
>
> class Category cat where
>   id  :: cat a a
>   (.) :: cat b c -> cat a b -> cat a c
>
> -- We need the projections from pairs:
>
> type family Fst (x :: (a, b)) :: a
> type instance Fst '(a, b) = a
>
> type family Snd (x :: (a, b)) :: b
> type instance Snd '(a, b) = b
>
> -- Now a morphism in the product category of `c` and `d` is a pair of
> -- a morphism in `c` and a morphism in `d`. Since the objects `s` and
> -- `t` are pairs, we can project out their components:
>
> data Product c d s t = Product (Fst s `c` Fst t) (Snd s `d` Snd t)
>
>
> With these definitions, your instance below is accepted.
>
>
> > Ideally I'd like to be able to express something like -
> >
> > instance (Category a, Category b) => Category (Product a b) where
> > id = Product id id
> > Product o1 o2 . Product i1 i2 = Product (o1 . i1) (o2 . i2)
> >
> > However, it all falls apart when I actually try to define anything. Is
> > this possible? If not, why not?
>
> Does the above help, or were you stuck on something else?
>
>
> > As far as I can tell the issue boils down to not being able to translate
> > "Category i o" to "Product (Fst i) (Fst o) (Snd i) (Snd o)" without
> > breaking the kind expectation of the category instance.
> >
> > Please help me, I'm having a bad brain day :-)
>
> Hopefully the above will let you get a bit further, although working
> with type-level pairs isn't always fun. At the moment, GHC doesn't
> support eta-expansion of pairs [4], so it can't prove that
>
>   x ~ (Fst x, Snd x)  for all  x :: (a, b)
>
> which rapidly becomes annoying when you try to work with constructions
> like the product category above.
>
> Adam
>
>
> > [1] - http://twanvl.nl/blog/haskell/categories-over-pairs-of-types
> > [2] -
> >
> http://hackage.haskell.org/packages/archive/categories/1.0.6/doc/html/Control-Category-Cartesian.html#t:Product
>
> [3] http://www.haskell.org/pipermail/libraries/2013-May/020127.html
> [4] http://hackage.haskell.org/trac/ghc/ticket/7259
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Product-Categories

2013-07-03 Thread Lyndon Maydwell
Hi Café.

I'm wracking my brain trying to figure out a simple, reasonably general,
implementation for a category instance for pairs of categories.

So far I've looked at [1], which seems great, but doesn't use the built-in
category instance, and [2], which I'm just not sure about.

Ideally I'd like to be able to express something like -

instance (Category a, Category b) => Category (Product a b) where
id = Product id id
Product o1 o2 . Product i1 i2 = Product (o1 . i1) (o2 . i2)

However, it all falls apart when I actually try to define anything. Is this
possible? If not, why not?

As far as I can tell the issue boils down to not being able to translate
"Category i o" to "Product (Fst i) (Fst o) (Snd i) (Snd o)" without
breaking the kind expectation of the category instance.

Please help me, I'm having a bad brain day :-)


[1] - http://twanvl.nl/blog/haskell/categories-over-pairs-of-types
[2] -
http://hackage.haskell.org/packages/archive/categories/1.0.6/doc/html/Control-Category-Cartesian.html#t:Product
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Hackage Update Brigade

2013-05-28 Thread Lyndon Maydwell
Done :)


On Wed, May 29, 2013 at 12:22 PM, Conrad Parker wrote:

> On 29 May 2013 08:54, Lyndon Maydwell  wrote:
> > How can I join the group?
>
> by asking any of the current members :) I've added you.
>
> > P.S. I've attached a simple image for the Gravatar if it looks okay.
>
> great, can you add it?
>
> Conrad.
>
> >
> >
> > On Tue, May 28, 2013 at 12:40 PM, Conrad Parker 
> > wrote:
> >>
> >> On 28 May 2013 05:29, Alexander Solla  wrote:
> >> > As per recent discussions, I'm making a list of volunteers who are
> >> > willing
> >> > to pick up some slack in Hackage package maintenance, so that we can
> >> > submit
> >> > an amendment to the Haskell Prime Committee's ticket 113
> >> > (http://hackage.haskell.org/trac/haskell-prime/ticket/113)
> >> >
> >> > I think that showing that people are willing to pick up missing
> package
> >> > maintainer's slack will alleviate the concern of breaking lots of code
> >> > by
> >> > refactoring the monad/applicative/functor hierarchy.  Code will be
> >> > broken,
> >> > but publicly available packages can be fixed by the community during a
> >> > "staging" period.  To that end, I have made a Google Form to collect
> >> > some
> >> > volunteer information.  If you are interested in helping, please
> visit:
> >> >
> >> >
> >> >
> https://docs.google.com/forms/d/1o4B8CEE_42u9f-sgmu2t5iSEvm0cq6-um6g_fHJt6GE/viewform
> >> >
> >> >
> >>
> >> For that proposal, there is also an informal github group for updating
> >> unmaintained packages,
> >> which anyone willing is welcome to join:
> >>
> >> https://github.com/haskell-pkg-janitors
> >>
> >> cheers,
> >>
> >> Conrad.
> >>
> >> ___
> >> Haskell-Cafe mailing list
> >> Haskell-Cafe@haskell.org
> >> http://www.haskell.org/mailman/listinfo/haskell-cafe
> >
> >
> >
> > ___
> > Haskell-Cafe mailing list
> > Haskell-Cafe@haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell-cafe
> >
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Hackage Update Brigade

2013-05-28 Thread Lyndon Maydwell
How can I join the group?

P.S. I've attached a simple image for the Gravatar if it looks okay.


On Tue, May 28, 2013 at 12:40 PM, Conrad Parker wrote:

> On 28 May 2013 05:29, Alexander Solla  wrote:
> > As per recent discussions, I'm making a list of volunteers who are
> willing
> > to pick up some slack in Hackage package maintenance, so that we can
> submit
> > an amendment to the Haskell Prime Committee's ticket 113
> > (http://hackage.haskell.org/trac/haskell-prime/ticket/113)
> >
> > I think that showing that people are willing to pick up missing package
> > maintainer's slack will alleviate the concern of breaking lots of code by
> > refactoring the monad/applicative/functor hierarchy.  Code will be
> broken,
> > but publicly available packages can be fixed by the community during a
> > "staging" period.  To that end, I have made a Google Form to collect some
> > volunteer information.  If you are interested in helping, please visit:
> >
> >
> https://docs.google.com/forms/d/1o4B8CEE_42u9f-sgmu2t5iSEvm0cq6-um6g_fHJt6GE/viewform
> >
> >
>
> For that proposal, there is also an informal github group for updating
> unmaintained packages,
> which anyone willing is welcome to join:
>
> https://github.com/haskell-pkg-janitors
>
> cheers,
>
> Conrad.
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
<>___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Hackage checking maintainership of packages

2013-05-06 Thread Lyndon Maydwell
Don't underestimate how greatly people appreciate being saved a couple of
minutes!


On Mon, May 6, 2013 at 8:01 PM, Niklas Hambüchen  wrote:

> On 06/05/13 17:46, Tillmann Rendel wrote:
> > So what about this: Hackage could try to automatically collect and
> > display information about the development status of packages that allow
> > potential users to *guess*
>
> In my opinion, that's what we have now.
>
> Obtaining the info in the four points you mention from their respective
> sources usually takes less than a minute in sum - hackage saving me that
> minute would give me little added value.
>
> Having the metrics you mention is nice, but still they are just metrics
> and say little the only thing that's important:
>
>Is there a human who commits themselves to this package?
>
> > I like the idea of displaying additional info about the status of
> > package development, but I don't like the idea of annoying hard-working
> > package maintainers with emails about their perfect packages
>
> I really think this is not too big of a deal, getting one email every 3
> months and clicking a few checkboxes.
>
> Probably fits into one cabal update.
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Hackage checking maintainership of packages

2013-05-05 Thread Lyndon Maydwell
But what if the package is already perfect?

Jokes aside, I think that activity alone wouldn't be a good indicator.


On Mon, May 6, 2013 at 9:59 AM, Conrad Parker  wrote:

> On 6 May 2013 09:42, Felipe Almeida Lessa  wrote:
> > Just checking the repo wouldn't work.  It may still have some activity
> > but not be maintained and vice-versa.
>
> ok, how about this: if the maintainer feels that their repo and
> maintenance activities are non-injective they can additionally provide
> an http-accessible URL for the maintenance activity. Hackage can then
> do an HTTP HEAD request on that URL and use the Last-Modified response
> header as an indication of the last time of maintenance activity. I'm
> being a bit tongue-in-cheek, but actually this would allow you to
> point hackage to a blog as evidence of maintenance activity.
>
> I like the idea of just pinging the code repo.
>
> Conrad.
>
> > On Sun, May 5, 2013 at 2:19 PM, Doug Burke  wrote:
> >>
> >> On May 5, 2013 7:25 AM, "Petr Pudlák"  wrote:
> >>>
> >>> Hi,
> >>>
> >>> on another thread there was a suggestion which perhaps went unnoticed
> by
> >>> most:
> >>>
>  -- Forwarded message --
>  From: Niklas Hambüchen 
>  Date: 2013/5/4
>  ...
>  I would even be happy with newhackage sending every package
> maintainer a
>  quarterly question "Would you still call your project X 'maintained'?"
>  for each package they maintain; Hackage could really give us better
>  indications concerning this.
> >>>
> >>>
> >>> This sounds to me like a very good idea. It could be as simple as "If
> you
> >>> consider yourself to be the maintainer of package X please just hit
> reply
> >>> and send." If Hackage doesn't get an answer, it'd just would display
> some
> >>> red text like "This package seems to be unmaintained since D.M.Y."
> >>>
> >>> Best regards,
> >>> Petr
> >>>
> >>
> >> For those packages that give a repository, a query could be done
> >> automatically to see when it was last updated. It's not the same thing
> as
> >> 'being maintained', but is less annoying for those people with many
> packages
> >> on hackage.
> >>
> >> Doug
> >>
> >>
> >> ___
> >> Haskell-Cafe mailing list
> >> Haskell-Cafe@haskell.org
> >> http://www.haskell.org/mailman/listinfo/haskell-cafe
> >>
> >
> >
> >
> > --
> > Felipe.
> >
> > ___
> > Haskell-Cafe mailing list
> > Haskell-Cafe@haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell-cafe
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Monad fold

2013-04-16 Thread Lyndon Maydwell
Yep. I was backstabbed by ghci seemingly having no issue with my definition
when I asked for the type.


On Tue, Apr 16, 2013 at 9:49 PM, Tom Ellis <
tom-lists-haskell-cafe-2...@jaguarpaw.co.uk> wrote:

> On Tue, Apr 16, 2013 at 01:53:19PM +0100, Oliver Charles wrote:
> > On 04/16/2013 01:47 PM, Lyndon Maydwell wrote:
> > >You could do:
> > >
> > >runKleisli . mconcat . map Kleisli :: Monoid (Kleisli m a b) => [a
> > >-> m b] -> a -> m b
> > >
> > >Would that work for you?
> > I can't find an instance for Monoid (Kleisli m a b) in `base`, so
> > presumably the author would also have to write this instance? If so
> > - would that really be any different to using that fold?
>
> It doesn't make sense anyway.  It would have to be "Kleisli m a a" which
> would presumably require a newtype.
>
> Tom
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Monad fold

2013-04-16 Thread Lyndon Maydwell
Wow looks like this Monoid instance isn't included in Control.Monad... My
mistake.


On Tue, Apr 16, 2013 at 8:47 PM, Lyndon Maydwell  wrote:

> You could do:
>
> runKleisli . mconcat . map Kleisli :: Monoid (Kleisli m a b) => [a -> m b]
> -> a -> m b
>
> Would that work for you?
>
>
> On Tue, Apr 16, 2013 at 8:35 PM, Christopher Howard <
> christopher.how...@frigidcode.com> wrote:
>
>> So, I'm doing something like this
>>
>> foldl (>>=) someA list :: Monad m => m a
>>
>> where
>>   list :: Monad m => [a -> m a],
>>   someA :: Monad m => m a
>>
>> Is there a more concise way to write this? I don't think foldM is what I
>> want -- or is it?
>>
>> --
>> frigidcode.com
>>
>>
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Monad fold

2013-04-16 Thread Lyndon Maydwell
You could do:

runKleisli . mconcat . map Kleisli :: Monoid (Kleisli m a b) => [a -> m b]
-> a -> m b

Would that work for you?


On Tue, Apr 16, 2013 at 8:35 PM, Christopher Howard <
christopher.how...@frigidcode.com> wrote:

> So, I'm doing something like this
>
> foldl (>>=) someA list :: Monad m => m a
>
> where
>   list :: Monad m => [a -> m a],
>   someA :: Monad m => m a
>
> Is there a more concise way to write this? I don't think foldM is what I
> want -- or is it?
>
> --
> frigidcode.com
>
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Optimal line length for haskell

2012-10-29 Thread Lyndon Maydwell
If I find my line is longer than 80 characters, I just shorten my
function and variable names!

It's perfectly idio(ma)tic!

On Mon, Oct 29, 2012 at 9:52 PM, Michael Orlitzky  wrote:
> On 10/29/2012 07:50 AM, Rustom Mody wrote:
>> There was a recent discussion on the python list regarding maximum line
>> length.
>> It occured to me that beautiful haskell programs tend to be plump (ie
>> have long lines) compared to other languages whose programs are 'skinnier'.
>> My thoughts on this are at
>> http://blog.languager.org/2012/10/layout-imperative-in-functional.html.
>>
>> Are there more striking examples than the lexer from the standard prelude?
>> [Or any other thoughts/opinions :-) ]
>
> In any language, a line longer than 80 characters usually (but not
> always) suggests that you might want to stop and rethink your design. In
> many cases a refactoring or two will greatly simplify the code and
> reduce your line length as a result.
>
> I think the lexer is an example of refactoring-needed rather than
> long-lines-needed.
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] 64-bit vs 32-bit haskell platform on Mac: misleading notice on Platform website?

2012-09-27 Thread Lyndon Maydwell
Carter:

Not yet.

I'll get round to it once I'm done with with an Agda presentation I'm
working on. Until then I can't afford to break my environment.

On Fri, Sep 28, 2012 at 1:56 PM, Carter Schonwald
 wrote:
> do these problems also happen if your'e using the glut backend? (because if
> its only glfw that has problems, then its something wrong in the ffi code,
> but if its both, that suggests there may be some sort of systematic
> problem?)
>
> @Lyndon, that sounds like a bug... especially since scotty seems to have no
> C code in package... have you filed a bug report with the maintainers thats
> reproducible?
>
>
> On Thu, Sep 27, 2012 at 3:49 AM, Lyndon Maydwell  wrote:
>>
>> I'm experiencing the same issues with compiled 64 bit working
>> correctly, but interpreted causing all sorts of issues with Scotty.
>>
>> On Thu, Sep 27, 2012 at 3:45 PM, Christiaan Baaij
>>  wrote:
>> > The behaviour seems to differ between versions of OS X.
>> >
>> > A student has OS X 10.8 installed and is observing the described
>> > behaviour:
>> > 32-bit: interpreted and compiled work correctly
>> > 64-bit: only compiled code works correctly
>> >
>> > However, I have OS X 10.6, and I'm observing the following behaviour:
>> > 32-bit: interpreted and compiled code work correctly
>> > 64-bit: interpreted and compiled code work correctly
>> >
>> > To test:
>> > cabal install gloss --flags="-GLUT GLFW"
>> > cabal unpack gloss-examples
>> > cd /picture/GameEvent
>> > ghci -fno-ghci-sandbox Main.hs
>> > main
>> >
>> > I'll try to find another OS X 10.8 install (I don't want to upgrade) and
>> > see if the behaviour still emerges.
>> >
>> >
>> > On Sep 26, 2012, at 11:03 PM, Carter Schonwald wrote:
>> >
>> >> really? does the 64 bit code work correctly when compiled?
>> >> if the compiled version works correctly, could you post a repo of some
>> >> example codlets that *should work* on ghc 7.6 so i can sort out if its
>> >> fixable.   There were some similar problems with gtk / cairo for a while 
>> >> on
>> >> OS X, and i was able to sort out reproducible instructions for getting
>> >> things to work in that case.
>> >
>> > ___
>> > Haskell-Cafe mailing list
>> > Haskell-Cafe@haskell.org
>> > http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] 64-bit vs 32-bit haskell platform on Mac: misleading notice on Platform website?

2012-09-27 Thread Lyndon Maydwell
I'm experiencing the same issues with compiled 64 bit working
correctly, but interpreted causing all sorts of issues with Scotty.

On Thu, Sep 27, 2012 at 3:45 PM, Christiaan Baaij
 wrote:
> The behaviour seems to differ between versions of OS X.
>
> A student has OS X 10.8 installed and is observing the described behaviour:
> 32-bit: interpreted and compiled work correctly
> 64-bit: only compiled code works correctly
>
> However, I have OS X 10.6, and I'm observing the following behaviour:
> 32-bit: interpreted and compiled code work correctly
> 64-bit: interpreted and compiled code work correctly
>
> To test:
> cabal install gloss --flags="-GLUT GLFW"
> cabal unpack gloss-examples
> cd /picture/GameEvent
> ghci -fno-ghci-sandbox Main.hs
> main
>
> I'll try to find another OS X 10.8 install (I don't want to upgrade) and see 
> if the behaviour still emerges.
>
>
> On Sep 26, 2012, at 11:03 PM, Carter Schonwald wrote:
>
>> really? does the 64 bit code work correctly when compiled?
>> if the compiled version works correctly, could you post a repo of some 
>> example codlets that *should work* on ghc 7.6 so i can sort out if its 
>> fixable.   There were some similar problems with gtk / cairo for a while on 
>> OS X, and i was able to sort out reproducible instructions for getting 
>> things to work in that case.
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell's type inference considered harmful [Re: [Haskell] A riddle...]

2012-07-17 Thread Lyndon Maydwell
You will be warned about the top-level definitions not including a
type-signature if you use the -Wall flag. This isn't really a complete
solution to your gripes, but it does address the change in behaviour
that you saw when adding/removing the commented code, and would draw
your attention to the logical error of trying to squeeze numbers that
were too large into a Word16.

I've been caught by unwarned truncation of numeric literals before
too, so it would be great if there were warnings for this.



On Tue, Jul 17, 2012 at 3:40 PM, Christopher Done  wrote:
> On 17 July 2012 09:27, Andreas Abel  wrote:
>>   1. Haskell's type inference is NON-COMPOSITIONAL!
>>
>> In the riddle below, I am defining two things f ("rgbliste") and g 
>> ("farbliste").  Even though they are not strongly connected, but g comes 
>> after f in the definition order, the code of g influences the type of f.  
>> THAT'S WRONG! :-(
>
>
> Bindings at the same level in Haskell are mutually recursive. Order of
> declaration does not matter. These two terms are unified by the type
> system. So I'm not sure what you expect to happen here.
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] [Haskell] A riddle...

2012-07-16 Thread Lyndon Maydwell
I'd guess that type-inference is allowing rgbliste to use Integers
when farbliste is commented out, but restricting it to 16 Bit types
when it is uncommented. I don't have the GTK module installed on this
machine, but try adding some type annotations to see if this is the
case.

The maxBound of Word16 appears to confirm my suspicion:

Prelude GHC.Word> maxBound :: Word16
65535

On Mon, Jul 16, 2012 at 11:36 PM, Vo Minh Thu  wrote:
> Oh the mailing list was haskell@ instead of café. Sorry. (Now cc'ing café.)
>
> Andreas, please post this kind of mail to the haskell-cafe instead of
> the haskell mailing list.
>
> 2012/7/16 Vo Minh Thu :
>> It seems like the infered type (and thus bounds) is different when you
>> force the result to be a Color or not. Just give explicit type
>> signatures and conversion functions.
>>
>> Cheers,
>> Thu
>>
>> 2012/7/16 Andreas Abel :
>>> Today a student came to me with a piece of code that worked it executed by
>>> itself, but produced different result in the context of his larger problem.
>>> We cut down the example to the following:
>>>
 import Graphics.UI.Gtk

 -- should produce [(26471,0,65535),...
 rgbliste =
  (map (\ i ->
   let rb = 5 * (mod (mod 181935629 (4534+i)) 100)-250+128 in
   let gb = 5 * (mod (mod 128872693 (5148+i)) 100)-250+128 in
   let bb = 5 * (mod (mod 140302469 (7578+i)) 100)-250+128 in
   let r = min 255 $ max 0 rb in
   let g = min 255 $ max 0 gb in
   let b = min 255 $ max 0 bb in
   (r*257,g*257,b*257)) [0..])

 --farbliste = map (\ (r,g,b) -> Color r g b) rgbliste

 main :: IO ()
 main = do
   print $ head rgbliste
>>>
>>>
>>> If you run it, it prints (26471,0,65535).
>>> If you uncomment the def. of farbliste, it prints (44461,65535,65535).
>>>
>>> I was surprised.  What is going on?
>>>
>>> Cheers,
>>> Andreas
>>>
>>> --
>>> Andreas Abel  <><  Du bist der geliebte Mensch.
>>>
>>> Theoretical Computer Science, University of Munich
>>> Oettingenstr. 67, D-80538 Munich, GERMANY
>>>
>>> andreas.a...@ifi.lmu.de
>>> http://www2.tcs.ifi.lmu.de/~abel/
>>>
>>>
>>> ___
>>> Haskell mailing list
>>> hask...@haskell.org
>>> http://www.haskell.org/mailman/listinfo/haskell
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Indent aware parser

2012-05-04 Thread Lyndon Maydwell
I'm not parsing Haskell, so the offside rule won't be required.

I'm looking at doing a more general Cassius parser.

On Fri, May 4, 2012 at 3:50 PM, S D Swierstra  wrote:
> The uulib package provides combinators for dealing with the Haskell offside 
> rule. Is that what you are looking for?
>
>  Doaitse
>
>
>
> Op 4 mei 2012 om 09:02 heeft Lyndon Maydwell  het 
> volgende geschreven:
>
>> Hi all.
>>
>> What's the best indentation-aware parser at the moment?
>>
>>
>> I see three when I look in cabal:
>>
>> lyndon@pugno:~ » cabal list indent
>> * IndentParser
>>    Synopsis: Combinators for parsing indentation based syntatic structures
>>    Default available version: 0.2.1
>>    Installed versions: [ Not installed ]
>>    Homepage: http://www.cse.iitk.ac.in/~ppk
>>    License:  GPL
>>
>> * indentparser
>>    Synopsis: A parser for indentation based structures
>>    Default available version: 0.1
>>    Installed versions: [ Not installed ]
>>    Homepage: http://www.cse.iitk.ac.in/users/ppk/code/HASKELL/indentparser
>>    License:  PublicDomain
>>
>> * indents
>>    Synopsis: indentation sensitive parser-combinators for parsec
>>    Default available version: 0.3.2
>>    Installed versions: [ Not installed ]
>>    Homepage: http://patch-tag.com/r/salazar/indents
>>    License:  BSD3
>>
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Indent aware parser

2012-05-04 Thread Lyndon Maydwell
Hi all.

What's the best indentation-aware parser at the moment?


I see three when I look in cabal:

lyndon@pugno:~ » cabal list indent
* IndentParser
Synopsis: Combinators for parsing indentation based syntatic structures
Default available version: 0.2.1
Installed versions: [ Not installed ]
Homepage: http://www.cse.iitk.ac.in/~ppk
License:  GPL

* indentparser
Synopsis: A parser for indentation based structures
Default available version: 0.1
Installed versions: [ Not installed ]
Homepage: http://www.cse.iitk.ac.in/users/ppk/code/HASKELL/indentparser
License:  PublicDomain

* indents
Synopsis: indentation sensitive parser-combinators for parsec
Default available version: 0.3.2
Installed versions: [ Not installed ]
Homepage: http://patch-tag.com/r/salazar/indents
License:  BSD3

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Data-Type Serialization

2012-04-22 Thread Lyndon Maydwell
Hi Café.

I'm pondering over an old chestnut that I'd forgotten about until recently.

I'd like to be able to express schemas for general recursive datatypes
(excluding functions and possibly encoding bounds) and have an
interactive constructor for that datatype generated automatically.
Originally this idea came about as an XML/JS framework for creating
advanced form inputs on the client-side, however, I'm interested in
how this could be implemented idiomatically in Haskell.

I'm guessing that the best way to go about this would be to capture
the declaration in template Haskell, having a passthrough for the
declaration itself, and also generating a representation that can be
used for introspection and the creation of the interactive component.
Ideally I'd like to integrate this concept into one of the
web-frameworks such as Yesod so that complicated data-types can be
constructed interactively on the client-side using (generated)
javascript in order to get instantaneous feedback about validity of
fields, etc, and avoid page reloads and even ajax communication. The
details of the web-side of things would probably be quite messy, but
if the Haskell side can be made general enough then this can be
considered a separate problem :-)

Has anyone had experience with trying to solve this, or a similar
issue? What approach did you take? Did you use Template-Haskell, or
something else?

Thanks!

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Building cabal-install for new ghc build

2012-04-16 Thread Lyndon Maydwell
Nice tip!

On Mon, Apr 16, 2012 at 4:42 PM, Daniël de Kok  wrote:
> On Apr 16, 2012, at 5:28 AM, Lyndon Maydwell wrote:
>> I've found that I had to make several modifications to the
>> bootstrap.sh and cabal-install.cabal files in order to get this to
>> work. I am wondering how the maintainers of the Haskell-platform, etc
>> are dealing with these issues.
>
> I usually get a recent cabal-install from the Cabal Darcs repository, which 
> normally builds without modifications to bootstrap.sh on a recent GHC:
>
> darcs get http://darcs.haskell.org/cabal/
>
> Or if you want a particular branch (such as 1.14):
>
> darcs get http://darcs.haskell.org/cabal-branches/cabal-1.14/
>
> Of course, you need Darcs to do this, but binary builds of Darcs are provided 
> on the Darcs website.
>
> -- Daniël

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Building cabal-install for new ghc build

2012-04-15 Thread Lyndon Maydwell
Hi Café.

I'm building GHC from package ghc-7.4.1-src.tar.bz2 as the binary
download was throwing segfaults for me (and apparently a few others).
This has worked well and my issues with GHC and GHCi are now resolved.
However I have needed to build cabal-install. This can't be done using
cabal-install because it isn't installed :)

I've found that I had to make several modifications to the
bootstrap.sh and cabal-install.cabal files in order to get this to
work. I am wondering how the maintainers of the Haskell-platform, etc
are dealing with these issues. There seems to be a cabal-install-7.4.1
package on Hackage to address these issues, but I couldn't get it to
work for me. Is this actually being used by the community?

I realize that I am making trouble for myself by not just using the
Haskell-Platform, but there are some packages I want to use that
depend on recent versions of base.

Thanks!

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Global Arrays

2012-03-09 Thread Lyndon Maydwell
Could template-Haskell be used somehow?

- Lyndon Maydwell
On Mar 10, 2012 4:50 AM, "Clark Gaebel"  wrote:

> In Haskell, what's the canonical way of declaring a top-level array
> (Data.Vector of a huge list of doubles, in my case)? Performance is
> key in my case.
>
> The straightforward way would just be something like:
>
> globalArray :: V.Vector Double
> globalArray = V.fromList [ huge list of doubles ]
> {-# NOINLINE globalArray #-}
>
> However, I don't want to have to run the fromList at runtime. Not only
> would this mean a bigger executable (having to store a linked list,
> instead of an array), it would be quite inefficient since we don't
> even use the source list!
>
> Therefore, I was thinking of storing the array in a C file:
>
> static const double globalArray[] = { huge list of doubles };
> double* getGlobalArray() { return globalArray; }
> intgetGlobalArraySize() { return
> sizeof(globalArray)/sizeof(globalArray[0]); }
>
> And importing it in haskell witht he FFI, followed with an unsafeCast:
>
> foreign import ccall unsafe "getGlobalArray" c_globalArray :: Ptr CDouble
> foreign import ccall unsafe "getGlobalArraySize" c_globalArraySize :: CInt
>
> globalArray :: V.Vector Double
> globalArray = V.unsafeCast $ unsafeFromForeignPtr0 (unsafePerformIO $
> newForeignPtr_ c_globalArray) (fromIntegral c_globalArraySize)
> {-# NOINLINE globalArray #-}
>
> But this version (clearly) is full of "unsafe"ty. Is there a better
> way that I haven't thought of?
>
> Regards,
>  - clark
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Conduit Error Output: Control.Monad.Trans.Resource.stateCleanup

2012-02-21 Thread Lyndon Maydwell
That makes a lot of sense.

The diff was a bit beyond my skimming abilities :-)

On Tue, Feb 21, 2012 at 4:15 PM, Michael Snoyman  wrote:
> Hi Lyndon,
>
> Outputting nothing *is* the desired result. When you run something like:
>
>    bar <- runResourceT $ lazyConsume $ sourceFile "foo.txt"
>    print bar
>
> The steps that occur are roughly[1]:
>
> * ResourceT is initialized
> * File handle is opened, release action is registered to close the file handle
> * unsafeInterleaveIO is called, which creates a thunk that will pull
> from the Handle
> * runResourceT is called, which calls all release actions, including
> closing the file handle
> * The thunk is evaluated. It checks if the ResourceT is open. Since it
> isn't, it returns a [].
>
> The problem previously is that the last step was not checking if the
> ResourceT was still open, which could result in pulling from a closed
> handle.
>
> Michael
>
> On Tue, Feb 21, 2012 at 9:57 AM, Lyndon Maydwell  wrote:
>> Hi Michael,
>>
>>
>> The behaviour of my original code has now changed to output nothing
>> with no errors. I'm not sure of the significance of this as my code
>> was incorrect, however, using the code you demonstrated gives the
>> desired results.
>>
>> Thanks for the blindingly quick response!
>>
>>
>> On Tue, Feb 21, 2012 at 3:30 PM, Michael Snoyman  wrote:
>>> On Tue, Feb 21, 2012 at 7:40 AM, Michael Snoyman  
>>> wrote:
>>>> On Tue, Feb 21, 2012 at 5:46 AM, Lyndon Maydwell  
>>>> wrote:
>>>>> Hi Michael, Café.
>>>>>
>>>>> I'm writing some code using the conduit library and am encountering
>>>>> the following error output (while the program appears to function
>>>>> correctly) when using Data.Conduit.Lazy.
>>>>>
>>>>> The error given is:
>>>>>
>>>>>> profile_simple_test_data: Control.Monad.Trans.Resource.stateCleanup: 
>>>>>> There is a bug in the implementation. The mutable state is being 
>>>>>> accessed after cleanup. Please contact the maintainers.
>>>>>
>>>>> A reduced code snippet that generates this error is (also attached):
>>>>>
>>>>>> import Control.Monad
>>>>>> import System.Environment
>>>>>> import Control.Monad.IO.Class (liftIO)
>>>>>> import System.IO
>>>>>> import Data.Conduit.Lazy
>>>>>> import Data.List (sort)
>>>>>>
>>>>>> import Data.Conduit
>>>>>>
>>>>>> import Prelude hiding (map)
>>>>>>
>>>>>> main = getArgs >>= process
>>>>>>
>>>>>> process args = mapM_ sorted args
>>>>>>
>>>>>> sorted x = runResourceT (lazyConsume $ sourceFeed x) >>= (mapM_ print . 
>>>>>> id)
>>>>>>
>>>>>> sourceFeed :: ResourceIO m => FilePath -> Source m String
>>>>>> sourceFeed file = sourceIO
>>>>>>     (openFile file ReadMode)
>>>>>>     hClose
>>>>>>     (\h -> liftIO $ do
>>>>>>         eof <- hIsEOF h
>>>>>>         if eof
>>>>>>             then return IOClosed
>>>>>>             else fmap IOOpen $ hGetLine h)
>>>>>
>>>>> when run over any text file.
>>>>>
>>>>> I may be doing something inconsistent with the correct use of sourceIO
>>>>> or lazyConsume, however, I tried to follow the example at
>>>>> http://www.yesodweb.com/home/snoyberg/blogs/conduit/conduit/source/source.ditamap?nav=nav-2
>>>>> as closely as possible.
>>>>>
>>>>> Is this a bug, or simply an incorrect use of Conduit?
>>>>
>>>> I haven't fully debugged this yet. There's certainly a bug in the
>>>> implementation of ResourceT, but the sample program is also wrong. You
>>>> can't pass the result from a call to lazyConsume outside the scope of
>>>> its ResourceT; the correct way to write sorted would be:
>>>>
>>>>    sorted x = runResourceT $ lazyConsume (sourceFeed x) >>= mapM_
>>>> (liftIO . print)
>>>>
>>>> My guess is that this is a fallout from the transition away from
>>>> mutable variables: lazyConsume no longer has any way of knowing that
>>>> its ResourceT has already been terminated. Perhaps a simple solution
>>>> would be to expose a primitive that checks if the ResourceT block has
>>>> already been finalized.
>>>>
>>>> Michael
>>>
>>> I've added a test case for this bug, and fixed it. The commit is:
>>>
>>> https://github.com/snoyberg/conduit/commit/87e890fe7ee58686d20cabba15dd37f18ba66620
>>>
>>> The basic idea is to add an extra constructor to represent when the
>>> ResourceT has already been closed, and expose a function
>>> resourceActive to check the state. Can you check if this solves your
>>> problem?
>>>
>>> Michael

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Conduit Error Output: Control.Monad.Trans.Resource.stateCleanup

2012-02-20 Thread Lyndon Maydwell
Hi Michael,


The behaviour of my original code has now changed to output nothing
with no errors. I'm not sure of the significance of this as my code
was incorrect, however, using the code you demonstrated gives the
desired results.

Thanks for the blindingly quick response!


On Tue, Feb 21, 2012 at 3:30 PM, Michael Snoyman  wrote:
> On Tue, Feb 21, 2012 at 7:40 AM, Michael Snoyman  wrote:
>> On Tue, Feb 21, 2012 at 5:46 AM, Lyndon Maydwell  wrote:
>>> Hi Michael, Café.
>>>
>>> I'm writing some code using the conduit library and am encountering
>>> the following error output (while the program appears to function
>>> correctly) when using Data.Conduit.Lazy.
>>>
>>> The error given is:
>>>
>>>> profile_simple_test_data: Control.Monad.Trans.Resource.stateCleanup: There 
>>>> is a bug in the implementation. The mutable state is being accessed after 
>>>> cleanup. Please contact the maintainers.
>>>
>>> A reduced code snippet that generates this error is (also attached):
>>>
>>>> import Control.Monad
>>>> import System.Environment
>>>> import Control.Monad.IO.Class (liftIO)
>>>> import System.IO
>>>> import Data.Conduit.Lazy
>>>> import Data.List (sort)
>>>>
>>>> import Data.Conduit
>>>>
>>>> import Prelude hiding (map)
>>>>
>>>> main = getArgs >>= process
>>>>
>>>> process args = mapM_ sorted args
>>>>
>>>> sorted x = runResourceT (lazyConsume $ sourceFeed x) >>= (mapM_ print . id)
>>>>
>>>> sourceFeed :: ResourceIO m => FilePath -> Source m String
>>>> sourceFeed file = sourceIO
>>>>     (openFile file ReadMode)
>>>>     hClose
>>>>     (\h -> liftIO $ do
>>>>         eof <- hIsEOF h
>>>>         if eof
>>>>             then return IOClosed
>>>>             else fmap IOOpen $ hGetLine h)
>>>
>>> when run over any text file.
>>>
>>> I may be doing something inconsistent with the correct use of sourceIO
>>> or lazyConsume, however, I tried to follow the example at
>>> http://www.yesodweb.com/home/snoyberg/blogs/conduit/conduit/source/source.ditamap?nav=nav-2
>>> as closely as possible.
>>>
>>> Is this a bug, or simply an incorrect use of Conduit?
>>
>> I haven't fully debugged this yet. There's certainly a bug in the
>> implementation of ResourceT, but the sample program is also wrong. You
>> can't pass the result from a call to lazyConsume outside the scope of
>> its ResourceT; the correct way to write sorted would be:
>>
>>    sorted x = runResourceT $ lazyConsume (sourceFeed x) >>= mapM_
>> (liftIO . print)
>>
>> My guess is that this is a fallout from the transition away from
>> mutable variables: lazyConsume no longer has any way of knowing that
>> its ResourceT has already been terminated. Perhaps a simple solution
>> would be to expose a primitive that checks if the ResourceT block has
>> already been finalized.
>>
>> Michael
>
> I've added a test case for this bug, and fixed it. The commit is:
>
> https://github.com/snoyberg/conduit/commit/87e890fe7ee58686d20cabba15dd37f18ba66620
>
> The basic idea is to add an extra constructor to represent when the
> ResourceT has already been closed, and expose a function
> resourceActive to check the state. Can you check if this solves your
> problem?
>
> Michael

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Conduit Error Output: Control.Monad.Trans.Resource.stateCleanup

2012-02-20 Thread Lyndon Maydwell
Hi Michael, Café.

I'm writing some code using the conduit library and am encountering
the following error output (while the program appears to function
correctly) when using Data.Conduit.Lazy.

The error given is:

> profile_simple_test_data: Control.Monad.Trans.Resource.stateCleanup: There is 
> a bug in the implementation. The mutable state is being accessed after 
> cleanup. Please contact the maintainers.

A reduced code snippet that generates this error is (also attached):

> import Control.Monad
> import System.Environment
> import Control.Monad.IO.Class (liftIO)
> import System.IO
> import Data.Conduit.Lazy
> import Data.List (sort)
>
> import Data.Conduit
>
> import Prelude hiding (map)
>
> main = getArgs >>= process
>
> process args = mapM_ sorted args
>
> sorted x = runResourceT (lazyConsume $ sourceFeed x) >>= (mapM_ print . id)
>
> sourceFeed :: ResourceIO m => FilePath -> Source m String
> sourceFeed file = sourceIO
> (openFile file ReadMode)
> hClose
> (\h -> liftIO $ do
> eof <- hIsEOF h
> if eof
> then return IOClosed
> else fmap IOOpen $ hGetLine h)

when run over any text file.

I may be doing something inconsistent with the correct use of sourceIO
or lazyConsume, however, I tried to follow the example at
http://www.yesodweb.com/home/snoyberg/blogs/conduit/conduit/source/source.ditamap?nav=nav-2
as closely as possible.

Is this a bug, or simply an incorrect use of Conduit?


conduit_error.hs
Description: Binary data
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Command Line Tools for Xcode

2012-02-16 Thread Lyndon Maydwell
Hi Café.


Has anyone read the news at http://kennethreitz.com/xcode-gcc-and-homebrew.html?

It looks like Apple is going to support a minimalist command-line
based toolchain for Xcode called "Command Line Tools for Xcode" based
on the OSX-GCC-Installer project.

Would Haskell support this rather than requiring a full Xcode install?
The requirement of Xcode has always struck me as quite onerous,
however this weighs in at around 200M - Much nicer!

I'm having issues logging in to the apple developer center at the
moment and was wondering if anyone had tried it out.


Thanks!

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] strict, lazy, non-strict, eager

2011-12-24 Thread Lyndon Maydwell
I wonder how the arrival of an anonymous anecdote on IRC was the
smoking gun needed to justify calling out the Haskell community on its
cognitive dissonance. Surely you would need some statistical evidence,
a public display from a very prominent member, or some officially
endorsed stance to convince anyone that "Most" of a community behaves
a certain way.

I understand why someone might want to call us out on a lack of
rigour. However, I have no idea why someone would hold their tongue on
the matter due to a lack of evidence, then commence hostilities once a
disjointed quote off IRC appears...

Albert: Was it the straw that broke the camel's back?

On Sat, Dec 24, 2011 at 9:41 PM, Edward Z. Yang  wrote:
>> 1. a function f is strict if  f ⊥ = ⊥
>> 2. ⊥ represents any computation which does not terminate, i.e. an
>> exception or an infinite loop
>> 3. "strict" describes the denotational semantics
>>
>> People, could you please make up your mind already? It has been more
>> than 13 years.
>
> I have to admit, I'm a bit confused what the complaint is.
>
> Edward
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] If you'd design a Haskell-like language, what would you do different?

2011-12-21 Thread Lyndon Maydwell
I would make the 'type' symbol a single character ala Agda. For example,

  a : Int

If your users are writing a lot of types, make it easy!
On Dec 22, 2011 10:42 AM, "Alexander Solla"  wrote:

>
>
> On Tue, Dec 20, 2011 at 10:30 PM, Gregory Crosswhite <
> gcrosswh...@gmail.com> wrote:
>
>>
>> On Dec 21, 2011, at 2:24 PM, Alexander Solla wrote:
>>
>> I would rather have an incomplete semantic, and have all the incomplete
>> parts collapsed into something we call "bottom".  We can then be smart and
>> stay within a total fragment of the language (where bottom is guaranteed to
>> not occur).
>>
>>
>> But part of the whole point of including bottom in our semantics in the
>> first place is *exactly* to *enable* us to be smart enough to know when we
>> are staying within a total fragment of the language.  For example,
>> including bottom in our semantics allows us to make and prove statements
>> like
>>
>> fst (42,_|_) = 42
>>
>
> A proof:
>
> fst :: (a,a) -> a
> fst (a,b) = a
>
>
> and
>>
>> fst _|_ = _|_
>>
>
> This expression is basically non-sense.  Should we accept
> straight-forwardly ill-typed expressions like:
>
> data Strict a = Strict !a
> fst (Strict [1..])
>
> just because the argument is "strictly" a bottom? Bottom inhabits every
> type, but only vacuously.
>
> To be generous in my interpretation, I assume you mean something like:
>
>fst (_|_, 10) = _|_.
>
> That is still proved by
>fst (x,y) = x
>
> Things like seq, unsafeCoerce, and the like, are defined as (functions
> into) bottom in GHC.Prim, and the real semantic-changing magic they perform
> is done behind the scenes.  It cannot be expressed as Haskell in the same
> Haskell context it is used.  So assuming you mean something like:
>
>fst (seq [1..] (1,2))
>
> I must respond that you are using one of these magical keywords which
> change Haskell's semantics.  They should be avoided.
>
>
>
>>
>> Refusing to use bottom in our semantics doesn't make life better by
>> forcing us to stay within a total fragment of the language, it actually
>> makes life harder by removing from us a useful tool for knowing *how* to
>> stay within a total fragment of the language.
>>
>
> I am collapsing the semantics for "distinct" bottoms into a single bottom
> and noting that it has no interpretation as a Haskell value.
>
> Notice that this brings Haskell's type theory in line with ZF and typed
> set theories.  In those theories, bottom merely exists as a syntactic
> expression with no interpretation.  It is the proto-value which is not
> equal to itself.  We can say that it inhabits every type.  But that is only
> vacuously.  Bottom does not exist.
>
> We can stay in the total fragment of Haskell very easily, essentially by
> using my quotient construction for bottom:
>
>
> http://www.cse.chalmers.se/~nad/publications/danielsson-et-al-popl2006.html
>
> It requires a shift of point of view, from denotational semantics and
> "computational effects" (the things we're trying to avoid by going
> functional and lazy!) to the language of logic, proof, and interpretation.
>  It is possible, consistent, and much simpler conceptually and in use.
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Project Euler Problem 357 in Haskell

2011-11-08 Thread Lyndon Maydwell
Could Int be overflowing?

On Tue, Nov 8, 2011 at 7:21 PM, mukesh tiwari
 wrote:
> Hello all
> Being a Haskell enthusiastic , first I tried to solve this problem in
> Haskell but it running for almost 10 minutes on my computer but not getting
> the answer. A similar C++ program outputs the answer almost instant so could
> some one please tell me how to improve this Haskell program.
>
> import Control.Monad.ST
> import Data.Array.ST
> import Data.Array.Unboxed
> import Control.Monad
>
> prime :: Int -> UArray Int Bool
> prime n = runSTUArray $ do
>     arr <- newArray ( 2 , n ) True :: ST s ( STUArray s Int Bool )
>     forM_ ( takeWhile ( \x -> x*x <= n ) [ 2 .. n ] ) $ \i -> do
>         ai <- readArray arr i
>         when ( ai  ) $ forM_ [ i^2 , i^2 + i .. n ] $ \j -> do
>             writeArray arr j False
>
>     return arr
>
> pList :: UArray Int Bool
> pList = prime $  10 ^ 8
>
> divPrime :: Int -> Bool
> divPrime n = all ( \d -> if mod n d == 0 then pList ! ( d + div  n  d ) else
> True )  $  [ 1 .. truncate . sqrt . fromIntegral  $ n ]
>
>
> main = putStrLn . show . sum  $ [ if and [ pList ! i , divPrime . pred $ i ]
> then pred  i else 0 | i <- [ 2 .. 10 ^ 8 ] ]
>
>
> C++ program which outputs the answer almost instant.
>
> #include
> #include
> #include
> #define Lim 10001
> using namespace std;
>
> bool prime [Lim];
> vector v ;
>
> void isPrime ()
>  {
>   for( int i = 2 ; i * i <= Lim ; i++)
>if ( !prime [i]) for ( int j = i * i ; j <= Lim ; j += i ) 
> prime [j] = 1
> ;
>
>   for( int i = 2 ; i <= Lim ; i++) if ( ! prime[i] ) v.push_back( 
> i ) ;
>   //cout<   //for(int i=0;i<10;i++) cout<
>  }
>
> int main()
>   {
>   isPrime();
>   int n = v.size();
>   long long sum = 0;
>   for(int i = 0 ; i < n ; i ++)
>{
>   int k = v[i]-1;
>   bool f = 0;
>   for(int i = 1 ; i*i<= k ; i++)
>   if ( k % i == 0 && prime[ i + ( k / i ) ] )  { 
> f=1 ; break ; }
>
>   if ( !f ) sum += k;
>}
>   cout<   }
>
> Regards
> Mukesh Tiwari
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Up and Down the Latter of Abstraction

2011-10-12 Thread Lyndon Maydwell
Thank you for the correction Brent.

The Diagrams package is a wonderful project.

- Lyndon Maydwell
On Oct 13, 2011 2:03 AM, "Brent Yorgey"  wrote:

> On Wed, Oct 12, 2011 at 12:57:45PM +0800, Lyndon Maydwell wrote:
> >
> > The closest I've seen to this proces from Haskell seems to have come
> > from "luite" and co (correct me if I'm wrong) and their work on the
> > Diagrams package and its surrounding infrastructure [2], however,
> >
> > [2] - http://pnyf.inf.elte.hu/fp/Diagrams_en.xml
>
> Just to set the record straight: I am the primary author of the
> diagrams package (http://hackage.haskell.org/package/diagrams), which
> is unrelated to the link above.  What they have done is very cool but
> seems mostly pedagogical in nature; the diagrams package attempts to
> go much, much further as a real-world tool for constructing vector
> graphics. (Look for a new release soon! =)
>
> Luite Stegeman (luite on #haskell) has been working on something
> called "Wolfgang Lambda", similar in spirit to Mathematica's user
> interface, but it is also unrelated to the above link.  It's not
> released yet (not sure what the planned timeline is).
>
> -Brent
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Up and Down the Latter of Abstraction

2011-10-11 Thread Lyndon Maydwell
Hi Cafe.


I came across an interesting page about interactive abstraction called
"Up and Down the Latter of Abstraction" [1] while browsing
hacker-news.

Under the appendix "Tools & Implementation" Bret Victor ponders:

  "Perhaps language theorists will stop messing around with arrows and
dependent types, and start inventing languages suitable for
interactive development and discovery."

I don't subscribe to the idea that static guarantees and functional
characteristics are mutually exclusive to interactive development and
discovery and I think they may actually complement each other
extremely well, but this page certainly does sell the interactive
aspect very effectively.

The closest I've seen to this proces from Haskell seems to have come
from "luite" and co (correct me if I'm wrong) and their work on the
Diagrams package and its surrounding infrastructure [2], however,
their interactive demonstrations no longer seem to be online. Still,
the dominant interface seems to be web-based, and I feel that a native
environment for this kind of explorative interactive programming would
be more effective.

Other languages that seem to be especially effective at this kind of
development are Processing [3] and Mathematica [4].


Has anyone had experience with interactive development in Haskell?



[1] - http://worrydream.com/LadderOfAbstraction/

  -- "Appendix: Tools & Implementation"

[2] - http://pnyf.inf.elte.hu/fp/Diagrams_en.xml
[3] - http://processing.org/
[4] - http://www.wolfram.com/mathematica/

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] pattern matching instead of prelude.head

2011-09-15 Thread Lyndon Maydwell
Pattern matching will warn you if you neglect to consider the empty list.

On Fri, Sep 16, 2011 at 10:24 AM, Michael Litchard  wrote:
> Someone commented on StackOverflow that pattern matching the first
> element of a list was preferable to head. This makes sense
> intuitively. Could someone articulate the reason why this is true?
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to implement the mean function

2011-06-30 Thread Lyndon Maydwell
The problem is that you need to convert (length xs) to a Num, then
return a Fractional.

On Fri, Jul 1, 2011 at 2:07 PM, Nathan Howell  wrote:
> (/) operates on a Fractional instance... but length returns an Int, which is
> not a Fractional.
> You can convert the Int to a Fractional instance:
> mean xs = sum xs / fromIntegral (length xs)
> or try an integer division:
> mean xs = sum xs `div` length xs
> -n
> On Thu, Jun 30, 2011 at 10:55 PM, Ruohao Li  wrote:
>>
>> Hi guys,
>> I just started learning some Haskell. I want to implement a mean function
>> to compute the mean of a list. The signature of the function is:
>> mean :: (Num a, Fractional b) => [a] -> b
>> But when I implement this simple function, the compiler keep whining at me
>> on type errors. I know this is wrong:
>> mean xs = sum xs / length xs
>> But how to get it right? Thanks.
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell Weekly News: Issue 187

2011-06-23 Thread Lyndon Maydwell
It's probably obvious, but is there a reason why the links in this
email are being minimised?


On Thu, Jun 23, 2011 at 11:08 AM, Daniel Santa Cruz  wrote:
>   Welcome to issue 187 of the HWN, a newsletter covering developments in
>   the Haskell community. This release covers the week of June 12 to 18,
>   2011.
>
> Announcements
>
>   Ian Lynagh announced a new patchlevel release of GHC (7.0.4). "This
>   release contains a handful of bugfixes relative to 7.0.3, so we
>   recommend upgrading."
>   http://goo.gl/hOvdA
>
>   Nicolas Wu released the third instance fo Haskell Parallel Digest.
>   Many thanks to Nick and Eric for putting this together.
>   http://goo.gl/s5muy
>
>   Jeroen Janssen invited us to the 8th Ghent Functional Programming
>   Group Meeting, to be held on Thursday, the 30th of June, in the
>   Technicum building of Ghent University.
>   http://goo.gl/G081Q
>
> Quotes of the Week
>
>   * monochrom: if I were dying to learn covariance, I would not be
>     looking for entertainment, like, I'm dying, I only have 5 minutes
>     to learn covariance, thank you very much
>
>   * hpc: the categorical dual of a hippomorphism should be a
>     giraffomorphism
>
>   * ksf: but, as, maybe indeed or not apparently, english, in, or
>     especially in, punctuation matters is an utter mess.
>
>   * 00:56:03  @faq can haskell tell if I am
>       lagging [...]
>     00:57:18  The answer is: Yes! Haskell can
>       do that.
>
> Top Reddit Stories
>
>   * Haskell: the Craft of Functional Programming, 3rd edition is out!
>     Domain: haskellcraft.com, Score: 44, Comments: 10
>     On Reddit: http://goo.gl/6ZInj
>     Original: http://goo.gl/t0GAX
>
>   * GHC 7.0.4 is out
>     Domain: haskell.org, Score: 42, Comments: 2
>     On Reddit: http://goo.gl/oxSJH
>     Original: http://goo.gl/EzWUP
>
>   * SafeHaskell pushed into GHC
>     Domain: haskell.org, Score: 39, Comments: 5
>     On Reddit: http://goo.gl/sOrjr
>     Original: http://goo.gl/2Rw56
>
>   * Minimum footprint for a GHC program: or, think about your TSOs
>     Domain: stackoverflow.com, Score: 23, Comments: 0
>     On Reddit: http://goo.gl/eIF0o
>     Original: http://goo.gl/dRgLG
>
>   * Pieces of Yesod: Inverting a Haskell Function
>     Domain: chplib.wordpress.com, Score: 21, Comments: 8
>     On Reddit: http://goo.gl/NFJNH
>     Original: http://goo.gl/x2cz2
>
>   * The 2011 ICFP contest is starting in just 6 hours!
>     Domain: icfpcontest.org, Score: 20, Comments: 15
>     On Reddit: http://goo.gl/BS7XI
>     Original: http://goo.gl/oqj0Y
>
>   * A pattern for avoiding allocation : Inside T5
>     Domain: blog.ezyang.com, Score: 19, Comments: 12
>     On Reddit: http://goo.gl/thuRP
>     Original: http://goo.gl/IZCIh
>
>   * Package of the Day: an improved runghc for fast repeated runs
>     Domain: hackage.haskell.org, Score: 16, Comments: 9
>     On Reddit: http://goo.gl/k6mQK
>     Original: http://goo.gl/a0DAC
>
>   * The Supero Supercompiler
>     Domain: community.haskell.org, Score: 16, Comments: 2
>     On Reddit: http://goo.gl/vBeFO
>     Original: http://goo.gl/3QsmC
>
>   * Galois Video: Building an Open-Source Autonomous Quad-Copter
>     Domain: corp.galois.com, Score: 15, Comments: 3
>     On Reddit: http://goo.gl/HZghO
>     Original: http://goo.gl/6AcMw
>
> Top StackOverflow Questions
>
>   * Why does performGC fail to release all memory?
>     votes: 17, answers: 2
>     Read on SO: http://goo.gl/dRgLG
>
>   * OSX, ghci, dylib, what is the correct way?
>     votes: 17, answers: 1
>     Read on SO: http://goo.gl/0s9Tu
>
>   * Why does Haskell's `head` crash on an empty list (or why
> *doesn't* it return an empty list)? (Language philosophy)
>     votes: 15, answers: 6
>     Read on SO: http://goo.gl/tghQR
>
>   * Towards understanding CodeGen* in the Haskell LLVM bindings
>     votes: 13, answers: 1
>     Read on SO: http://goo.gl/LPZ2F
>
>   * What happens to you if you break the monad laws?
>     votes: 13, answers: 3
>     Read on SO: http://goo.gl/Trvny
>
>   * Is anyone using delimited continuations to do web development in Haskell?
>     votes: 12, answers: 3
>     Read on SO: http://goo.gl/hGjuB
>
>   * The concept of Bottom in Haskell
>     votes: 12, answers: 1
>     Read on SO: http://goo.gl/9b1ZJ
>
> About the Haskell Weekly News
>
>   To help create new editions of this newsletter, please send stories to
>   dstc...@gmail.com.
>
>   Until next time,
>   Daniel Santa Cruz
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Conditional IO ?

2011-06-20 Thread Lyndon Maydwell
Your errors branch has the type

writeFile "parse-errors.txt" (show errors) :: IO ()

This means that your otherwise branch should have the same type.

You can use the return function that has the type

return :: Monad m => a -> m a

specialised to m = IO

in conjunction with the value

() :: ()

giving

return () :: IO ()

There is also the when function that eliminates the else case for
conditional IO:
http://hackage.haskell.org/packages/archive/base/latest/doc/html/Control-Monad.html#v:when

On Mon, Jun 20, 2011 at 4:00 PM, Dmitri O.Kondratiev  wrote:
> Hi,
> What is right way to do conditional IO?
> For example, I need to write to file errors only in case they exist,
> otherwise my function should do nothing:
>
> handleParseErrors errors
>   | (not . null) errors =  writeFile "parse-errors.txt" (show errors)
>   | otherwise = ?
>
> What should be an 'otherwise' case ?
>
> Thanks!
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Generating simple histograms in png format?

2011-06-12 Thread Lyndon Maydwell
It might not be a perfect fit, but I've found the Diagrams useful for
plotting these kind of things recently.

On Sun, Jun 12, 2011 at 11:08 PM, Eric Rasmussen
 wrote:
> There is a program written in Haskell called Timeplot that does this:
> http://www.haskell.org/haskellwiki/Timeplot
>
> It's an executable rather than a library, but you can use your own Haskell
> code to preprocess/format data and pipe it to the program to generate
> histograms as pngs.
>
> Best,
> Eric
>
>
> On Sun, Jun 12, 2011 at 6:40 AM, C K Kashyap  wrote:
>>
>> You might find this useful
>> - http://www.haskell.org/haskellwiki/Library/PNG
>> Btw, I too am looking for such a library.
>> Regards,
>> Kashyap
>>
>> On Sat, Jun 11, 2011 at 3:32 AM, Dmitri O.Kondratiev 
>> wrote:
>>>
>>> I am looking for platform-independent library to generate simple
>>> histograms in png format.
>>> Does such thing exist?
>>>
>>> Thanks!
>>>
>>> ___
>>> Haskell-Cafe mailing list
>>> Haskell-Cafe@haskell.org
>>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>>
>>
>>
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Maybe use advice

2011-06-07 Thread Lyndon Maydwell
I was considering using a matrix optimisation but things are out of
control enough already :)

Converting all Changes constructors to nested regular constructors may
be the easiest approach. It would certainly eliminate the mess of list
manipulations.

On Tue, Jun 7, 2011 at 6:21 PM, John Lato  wrote:
> If I'm interpreting your code properly, it's not currently catching that
> case anyway.
> The problem is that you've got two sets of modifiers that both should be
> optimized, explicit Modifier constructors in the Image, and a list contained
> in Changes.  Since 'Changes' is just a list of Modifiers, and not an Image,
> neither rewrite nor transform will descend on it.  You get around this by
> explicitly calling rewrite on the modifiers in 'deBlank', but then the rules
> from 'optimize' aren't applied.  You can't really use the biplate functions
> either because they only match on a single element at a time.  What you
> really want to do is be able to express each rule exactly once, which isn't
> possible in the current form of your code.
> One solution is to move a lot of the reductions of the form 'Modifier x'
> from 'optimize' into 'deBlank'.  Then you would have something like this:
>
>> deBlank :: [Modifier] -> [Modifier]
>> deBlank = db
>>
>> db (Scale 1 1 : l)   = db l
>> db (Rotate x : Rotate x' : l) = db (Rotate (x+x') : l)
>> db (Scale  x y : Scale x' y' : l) = db (Scale (x*x') (y*y') : l)
>> db (Translate x y : Translate x' y' : l) = db (Translate (x+x') (y+y') :
>> l)
>> db xs = xs
>
> I actually don't think uniplate gets you anything in this particular
> function.
> Now deBlank will produce a list of modifiers which is as reduced as possible
> (at least by the rules you've provided), and you can use it within a
> two-pass optimize:
>> optimize = transform o2 . transform o
>>
>> o (Modifier _ Blank) = Blank
>> o (Modifier (Scale 0 _) _i) = Blank
>> -- similar cases omitted
>>
>> o (Modifier m2 (Modifier m1 i)) = Modifier (m1 `mappend` m2) i
>> o i@(Modifier (Changes _c) _i) = i
>> o (Modifier m i) = Modifier (Changes [m]) i
>> o i = i
>>
>> o2 (Modifier (Changes c) i) = case deBlank c of
>>      [] -> i
>>      [x] -> Modifier x i
>>      xs -> Modifier (Changes c) i
>> o2 i = i
> Transformations like "Scale 0 _" have remained in the Image traversal,
> however all other modifications are combined into a single Changes list,
> which is then reduced by deBlank in the second pass.  Note that in the first
> pass, even single modifications are encapsulated in a Changes; this makes
> the logic of the second pass much simpler because then all the reductions of
> multiple modifiers are located in the 'deBlank' function instead of split
> between there and 'o'.
> This presumes there's an appropriate Monoid instance for Modifiers, but if
> it doesn't exist it can be written easily enough.
> On second thought, I think it would be good to break it up even more, and
> keep the reductions of the form
>> o (Modifier _ Blank) = Blank
>> o (Modifier (Scale 0 _) _i) = Blank
> as a third pass, because it's possible some of them could get lost in this
> form.  Then  the first pass would just combine terms, the second would apply
> 'deBlank' and reduce, then the third would be as above.
> There are two alternatives which may be simpler:
> 1)  Expand "Changes c" into explicit modifications and do all your
> reductions on the resulting Image.
> 2)   Implement a general matrix transform for Diagrams and rewrite
> everything in terms of that.  This would be useful for shear transforms
> anyway, which I believe are currently inexpressible in Diagrams.
> John Lato
> On Tue, Jun 7, 2011 at 10:12 AM, Lyndon Maydwell  wrote:
>>
>> The fixpoint nature of rewrite catches some cases that transform might
>> not if I'm interpreting it correctly.
>>
>> (Changes [Translate 1 1, Scale 1 1, Translate 1 1]) could be rewritten
>> as (Translate 2 2), but I'm not sure that it could be translated as
>> such if it matches against (Changes [Translate _ _, Translate _ _])
>> first.
>>
>> I have the code on github at
>>
>> https://github.com/sordina/Diagrams-AST/blob/master/src/Graphics/Rendering/Diagrams/AST/Optimize.hs
>> if you're interested.
>>
>> At the moment I'm not worrying about speed as I really just wrote this
>> optimisation function as a demo of why an AST interface to Diagrams
>> might be useful.
>

Re: [Haskell-cafe] Maybe use advice

2011-06-07 Thread Lyndon Maydwell
The fixpoint nature of rewrite catches some cases that transform might
not if I'm interpreting it correctly.

(Changes [Translate 1 1, Scale 1 1, Translate 1 1]) could be rewritten
as (Translate 2 2), but I'm not sure that it could be translated as
such if it matches against (Changes [Translate _ _, Translate _ _])
first.

I have the code on github at
https://github.com/sordina/Diagrams-AST/blob/master/src/Graphics/Rendering/Diagrams/AST/Optimize.hs
if you're interested.

At the moment I'm not worrying about speed as I really just wrote this
optimisation function as a demo of why an AST interface to Diagrams
might be useful.

On Tue, Jun 7, 2011 at 5:06 PM, John Lato  wrote:
> Is it necessary (helpful) to use 'rewrite'?  Nearly every time I've tried
> it, in the end 'transform' has been a better choice.  Then you wouldn't need
> the 'Just's at all, and it should work fine.
> John
>
>>
>> From: Lyndon Maydwell 
>>
>> (missed including cafe)
>>
>> f :: [Modification] -> Maybe [Modification]
>> and
>> f _ = Just $ f ...
>> are incompatible
>>
>> I managed to get the behaviour I'm after with the use of Either, but
>> this really is messy:
>>
>>
>> -- Sets of changes
>> o (Modifier (Changes [])  i) = Just $ i
>> o (Modifier (Changes [c]) i) = Just $ Modifier c i
>> o (Modifier (Changes l)   i) = g (f (Left l))
>>  where
>>    g (Right l) = Just $ Modifier (Changes l) i
>>    g (Left  l) = Nothing
>>
>>    f (Left  (Scale     x y : Scale     x' y' : l)) =
>>        f $ Right $ Scale     (x*x') (y*y') : h (f $ Left l)
>>    f (Left  (Translate x y : Translate x' y' : l)) =
>>        f $ Right $ Translate (x+x') (y+y') : h (f $ Left l)
>>    f (Left  (Rotate    x   : Rotate    x'    : l)) =
>>        f $ Right $ Rotate    (x+x')        : h (f $ Left l)
>>    f x = x
>>
>>    h (Left  l) = l
>>    h (Right l) = l
>>
>>
>> On Tue, Jun 7, 2011 at 3:11 AM, Maciej Marcin Piechotka
>>  wrote:
>> > On Mon, 2011-06-06 at 23:38 +0800, Lyndon Maydwell wrote:
>> >> I'm writing an optimisation routine using Uniplate. Unfortunately, a
>> >> sub-function I'm writing is getting caught in an infinite loop because
>> >> it doesn't return Nothing when there are no optimisations left.
>> >>
>> >> I'd like a way to move the last Just into f, but this makes recursion
>> >> very messy. I was wondering if there was a nice way to use something
>> >> like the Monad or Applicative instance to help here.
>> >>
>> >> -- Sets of changes
>> >> o (Modifier (Changes []) ?i) = Just $ i
>> >> o (Modifier (Changes [c]) i) = Just $ Modifier c i
>> >> o (Modifier (Changes l) ? i) = Just $ Modifier (Changes (f l)) i
>> >> ? where
>> >> ? ? f (Scale ? ? x y : Scale ? ? x' y' : l) = f $ Scale ? ? (x*x')
>> >> (y*y') : f l
>> >> ? ? f (Translate x y : Translate x' y' : l) = f $ Translate (x+x')
>> >> (y+y') : f l
>> >> ? ? f (Rotate ? ?x ? : Rotate ? ?x' ? ?: l) = f $ Rotate ? ?(x+x') ? ?
>> >> ? ?: f l
>> >> ? ? f l = l
>> >>
>> >>
>> >> Any ideas?
>> >
>> > Something like:
>> >
>> > ...
>> > f (Rotate ? ?x ? : Rotate ? ?x' ? ?: l)
>> > ? ?= Just $ f (Rotate (x+x') : fromMaybe l (f l))
>> > f l = Nothing -- As far as I understend
>> >
>> > Regards
>> >
>> > ___
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Maybe use advice

2011-06-06 Thread Lyndon Maydwell
Thanks Maciej!

An additional Just was required in the refactored version of f:

f (Rotatex   : Rotatex': cs) = Just $ g (Rotate (x+x') : g cs)

This is much cleaner than what I was doing.


On Tue, Jun 7, 2011 at 4:14 AM, Maciej Piechotka  wrote:
> On Tue, 2011-06-07 at 04:09 +0800, Lyndon Maydwell wrote:
>> (missed including cafe)
>>
>> f :: [Modification] -> Maybe [Modification]
>> and
>> f _ = Just $ f ...
>> are incompatible
>>
>
>
> My bad:
>
> f ... = let cs' = (Rotate (x+x') : fromMaybe cs (f cs))
>        in fromMaybe cs (f cs)
>
> Or refactoring it:
>
> g l = fromMaybe l (f l)
>
> f (Rotate    x   : Rotate    x'    : cs) = g (Rotate (x+x') : g cs)
>
> Regards
>
>> I managed to get the behaviour I'm after with the use of Either, but
>> this really is messy:
>>
>>
>> -- Sets of changes
>> o (Modifier (Changes [])  i) = Just $ i
>> o (Modifier (Changes [c]) i) = Just $ Modifier c i
>> o (Modifier (Changes l)   i) = g (f (Left l))
>>   where
>>     g (Right l) = Just $ Modifier (Changes l) i
>>     g (Left  l) = Nothing
>>
>>     f (Left  (Scale     x y : Scale     x' y' : l)) =
>>         f $ Right $ Scale     (x*x') (y*y') : h (f $ Left l)
>>     f (Left  (Translate x y : Translate x' y' : l)) =
>>         f $ Right $ Translate (x+x') (y+y') : h (f $ Left l)
>>     f (Left  (Rotate    x   : Rotate    x'    : l)) =
>>         f $ Right $ Rotate    (x+x')        : h (f $ Left l)
>>     f x = x
>>
>>     h (Left  l) = l
>>     h (Right l) = l
>>
>>
>> On Tue, Jun 7, 2011 at 3:11 AM, Maciej Marcin Piechotka
>>  wrote:
>> > On Mon, 2011-06-06 at 23:38 +0800, Lyndon Maydwell wrote:
>> >> I'm writing an optimisation routine using Uniplate. Unfortunately, a
>> >> sub-function I'm writing is getting caught in an infinite loop because
>> >> it doesn't return Nothing when there are no optimisations left.
>> >>
>> >> I'd like a way to move the last Just into f, but this makes recursion
>> >> very messy. I was wondering if there was a nice way to use something
>> >> like the Monad or Applicative instance to help here.
>> >>
>> >> -- Sets of changes
>> >> o (Modifier (Changes [])  i) = Just $ i
>> >> o (Modifier (Changes [c]) i) = Just $ Modifier c i
>> >> o (Modifier (Changes l)   i) = Just $ Modifier (Changes (f l)) i
>> >>   where
>> >>     f (Scale     x y : Scale     x' y' : l) = f $ Scale     (x*x') (y*y') 
>> >> : f l
>> >>     f (Translate x y : Translate x' y' : l) = f $ Translate (x+x') (y+y') 
>> >> : f l
>> >>     f (Rotate    x   : Rotate    x'    : l) = f $ Rotate    (x+x')        
>> >> : f l
>> >>     f l = l
>> >>
>> >>
>> >> Any ideas?
>> >
>> > Something like:
>> >
>> > ...
>> > f (Rotate    x   : Rotate    x'    : l)
>> >    = Just $ f (Rotate (x+x') : fromMaybe l (f l))
>> > f l = Nothing -- As far as I understend
>> >
>> > Regards
>> >
>> > ___
>> > Haskell-Cafe mailing list
>> > Haskell-Cafe@haskell.org
>> > http://www.haskell.org/mailman/listinfo/haskell-cafe
>> >
>> >
>
>
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Maybe use advice

2011-06-06 Thread Lyndon Maydwell
(missed including cafe)

f :: [Modification] -> Maybe [Modification]
and
f _ = Just $ f ...
are incompatible

I managed to get the behaviour I'm after with the use of Either, but
this really is messy:


-- Sets of changes
o (Modifier (Changes [])  i) = Just $ i
o (Modifier (Changes [c]) i) = Just $ Modifier c i
o (Modifier (Changes l)   i) = g (f (Left l))
  where
g (Right l) = Just $ Modifier (Changes l) i
g (Left  l) = Nothing

f (Left  (Scale x y : Scale x' y' : l)) =
f $ Right $ Scale (x*x') (y*y') : h (f $ Left l)
f (Left  (Translate x y : Translate x' y' : l)) =
f $ Right $ Translate (x+x') (y+y') : h (f $ Left l)
f (Left  (Rotatex   : Rotatex': l)) =
f $ Right $ Rotate(x+x'): h (f $ Left l)
f x = x

h (Left  l) = l
h (Right l) = l


On Tue, Jun 7, 2011 at 3:11 AM, Maciej Marcin Piechotka
 wrote:
> On Mon, 2011-06-06 at 23:38 +0800, Lyndon Maydwell wrote:
>> I'm writing an optimisation routine using Uniplate. Unfortunately, a
>> sub-function I'm writing is getting caught in an infinite loop because
>> it doesn't return Nothing when there are no optimisations left.
>>
>> I'd like a way to move the last Just into f, but this makes recursion
>> very messy. I was wondering if there was a nice way to use something
>> like the Monad or Applicative instance to help here.
>>
>> -- Sets of changes
>> o (Modifier (Changes [])  i) = Just $ i
>> o (Modifier (Changes [c]) i) = Just $ Modifier c i
>> o (Modifier (Changes l)   i) = Just $ Modifier (Changes (f l)) i
>>   where
>>     f (Scale     x y : Scale     x' y' : l) = f $ Scale     (x*x') (y*y') : 
>> f l
>>     f (Translate x y : Translate x' y' : l) = f $ Translate (x+x') (y+y') : 
>> f l
>>     f (Rotate    x   : Rotate    x'    : l) = f $ Rotate    (x+x')        : 
>> f l
>>     f l = l
>>
>>
>> Any ideas?
>
> Something like:
>
> ...
> f (Rotate    x   : Rotate    x'    : l)
>    = Just $ f (Rotate (x+x') : fromMaybe l (f l))
> f l = Nothing -- As far as I understend
>
> Regards
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Maybe use advice

2011-06-06 Thread Lyndon Maydwell
I'm writing an optimisation routine using Uniplate. Unfortunately, a
sub-function I'm writing is getting caught in an infinite loop because
it doesn't return Nothing when there are no optimisations left.

I'd like a way to move the last Just into f, but this makes recursion
very messy. I was wondering if there was a nice way to use something
like the Monad or Applicative instance to help here.

-- Sets of changes
o (Modifier (Changes [])  i) = Just $ i
o (Modifier (Changes [c]) i) = Just $ Modifier c i
o (Modifier (Changes l)   i) = Just $ Modifier (Changes (f l)) i
  where
f (Scale x y : Scale x' y' : l) = f $ Scale (x*x') (y*y') : f l
f (Translate x y : Translate x' y' : l) = f $ Translate (x+x') (y+y') : f l
f (Rotatex   : Rotatex': l) = f $ Rotate(x+x'): f l
f l = l


Any ideas?

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to install GhC on a Mac without registering?

2011-06-06 Thread Lyndon Maydwell
I would be fantastic if XCode wasn't a dependency. As well as the
inconvenience it also weighs in at around 5G (IIRC) of space which is
still somewhat significant.

Not to detract at all from the work of the wonderful GHC and Haskell
Platform contributors in any way. For me it would just make it that
much easier to convince mac-using friends to give Haskell a try.

On Mon, Jun 6, 2011 at 4:49 PM, Richard O'Keefe  wrote:
>
> On 6/06/2011, at 8:11 AM, Chris Smith wrote:
>> That's interesting... whatever the reason, though, I concur that using
>> Haskell seems much easier on Linux and Windows.  I had to abandon a plan
>> to introduce Haskell in a class I taught this past semester because of
>> issues with getting it installed on the Macintosh laptops that some of
>> the students had.
>
> You can always
> (1) Install VirtualBox -- it's free.
> (2) Set up an Ubuntu VM inside VirtualBox -- Ubuntu is also free.
> (3) Install Haskell in Ubuntu.
>
> I've done exactly that on the Mac laptop I use.
> I also have Haskell running under Mac OS with no special problems.
>
>>  It's very unfortunate that Haskell on Mac requires
>> software which can neither be bundled in the install kit nor downloaded
>> freely from elsewhere.
>
> Note that the price for XCode applies to *XCode*.
> It's not a price for *GCC*.
> Having XCode, I was about to download GCC 4.5, build it,
> and install it in my own ~/local directory.
> Presumably, having built it, I could have copied it somewhere else.
>
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] What's the advantage of writing Haskell this way?

2011-05-31 Thread Lyndon Maydwell
Heh. Looks like there will be about five class constraints, but it
will still be more general.

There must be some higher level abstraction that is less ugly.

On Tue, May 31, 2011 at 3:45 PM, Yves Parès  wrote:
> Maybe you are looking for a more generic way to concatenate it:
> There is fold :: (Foldable t, Monoid m) => t m -> m in Data.Foldable, but it
> would add another Foldable constraint.
>
> You search a function like:
> concatMPlus :: (MonadPlus m, Monoid a) => m a -> a
> but this cannot exist ;) ("m a -> m a" would, but not "m a -> a")
>
>
> 2011/5/31 Lyndon Maydwell 
>>
>> I think this is because mconcat expects a list.
>>
>> On Tue, May 31, 2011 at 3:31 PM, John Ky  wrote:
>> > Thanks Malcom.
>> > I suspected that much, so I added it:
>> > data Stream m a
>> > = Chunks (m a)
>> > | EOF
>> > deriving (Show, Eq)
>> > instance (Monad m, MonadPlus m, Monoid (m a)) => Monoid (Stream m a)
>> > where
>> > mempty = Chunks mempty
>> > mappend (Chunks xs) (Chunks ys) = Chunks (xs `mappend` ys)
>> > mappend _ _ = EOF
>> > instance (Monad m, MonadPlus m) => Monad (Stream m) where
>> > return = Chunks . return
>> > Chunks xs >>= f = mconcat (fmap f xs)
>> > EOF >>= _ = EOF
>> > This gives me the error:
>> > Iteratee.hs:30:10:
>> >     Non type-variable argument in the constraint: Monoid (m a)
>> >     (Use -XFlexibleContexts to permit this)
>> >     In the context: (Monad m, MonadPlus m, Monoid (m a))
>> >     While checking the context of an instance declaration
>> >     In the instance declaration for `Monoid (Stream m a)'
>> > So I run with the new flag:
>> > ghci -XFlexibleContexts Iteratee.hs
>> > Then I get the following error instead:
>> > Iteratee.hs:37:43:
>> >     Could not deduce (m ~ [])
>> >     from the context (Monad m, MonadPlus m)
>> >       bound by the instance declaration at Iteratee.hs:35:10-51
>> >       `m' is a rigid type variable bound by
>> >           the instance declaration at Iteratee.hs:35:17
>> >     Expected type: [a]
>> >       Actual type: m a
>> >     In the second argument of `fmap', namely `xs'
>> >     In the first argument of `mconcat', namely `(fmap f xs)'
>> >     In the expression: mconcat (fmap f xs)
>> > Which is complaining about the line I highlighted above.  So I try:
>> > data Stream m a
>> > = Chunks (m a)
>> > | EOF
>> > deriving (Show, Eq)
>> > instance (Monad m, MonadPlus m, Monoid (m a)) => Monoid (Stream m a)
>> > where
>> > mempty = Chunks mempty
>> > mappend (Chunks xs) (Chunks ys) = Chunks (xs `mappend` ys)
>> > mappend _ _ = EOF
>> > instance (Monad m, MonadPlus m, Monoid (m a)) => Monad (Stream m) where
>> > return = Chunks . return
>> > Chunks xs >>= f = mconcat (fmap f xs)
>> > EOF >>= _ = EOF
>> > But the same trick doesn't work:
>> > Iteratee.hs:35:10:
>> >     Variable occurs more often in a constraint than in the instance head
>> >       in the constraint: Monoid (m a)
>> >     (Use -XUndecidableInstances to permit this)
>> >     In the instance declaration for `Monad (Stream m)'
>> > Is that because I don't use a on the right hand side of =>?
>> > Cheers,
>> > -John
>> > On 31 May 2011 15:54, Malcolm Wallace  wrote:
>> >>
>> >> instance (Monad m, MonadPlus m) => Monoid (Stream m a) where
>> >>
>> >> mempty = Chunks mempty
>> >> mappend (Chunks xs) (Chunks ys) = Chunks (xs `mappend` ys)
>> >> mappend _ _ = EOF
>> >>
>> >> Iteratee.hs:28:25:
>> >>     No instance for (Monoid (m a))
>> >>       arising from a use of `mempty'
>> >>
>> >> There is a clue in the first part of the error message.  Add the
>> >> required
>> >> instance as part of the predicate:
>> >> instance (Monad m, MonadPlus m, Monoid (m a)) => Monoid (Stream m a)
>> >> where
>> >> ...
>> >
>> > ___
>> > Haskell-Cafe mailing list
>> > Haskell-Cafe@haskell.org
>> > http://www.haskell.org/mailman/listinfo/haskell-cafe
>> >
>> >
>>
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] What's the advantage of writing Haskell this way?

2011-05-31 Thread Lyndon Maydwell
I think this is because mconcat expects a list.

On Tue, May 31, 2011 at 3:31 PM, John Ky  wrote:
> Thanks Malcom.
> I suspected that much, so I added it:
> data Stream m a
> = Chunks (m a)
> | EOF
> deriving (Show, Eq)
> instance (Monad m, MonadPlus m, Monoid (m a)) => Monoid (Stream m a) where
> mempty = Chunks mempty
> mappend (Chunks xs) (Chunks ys) = Chunks (xs `mappend` ys)
> mappend _ _ = EOF
> instance (Monad m, MonadPlus m) => Monad (Stream m) where
> return = Chunks . return
> Chunks xs >>= f = mconcat (fmap f xs)
> EOF >>= _ = EOF
> This gives me the error:
> Iteratee.hs:30:10:
>     Non type-variable argument in the constraint: Monoid (m a)
>     (Use -XFlexibleContexts to permit this)
>     In the context: (Monad m, MonadPlus m, Monoid (m a))
>     While checking the context of an instance declaration
>     In the instance declaration for `Monoid (Stream m a)'
> So I run with the new flag:
> ghci -XFlexibleContexts Iteratee.hs
> Then I get the following error instead:
> Iteratee.hs:37:43:
>     Could not deduce (m ~ [])
>     from the context (Monad m, MonadPlus m)
>       bound by the instance declaration at Iteratee.hs:35:10-51
>       `m' is a rigid type variable bound by
>           the instance declaration at Iteratee.hs:35:17
>     Expected type: [a]
>       Actual type: m a
>     In the second argument of `fmap', namely `xs'
>     In the first argument of `mconcat', namely `(fmap f xs)'
>     In the expression: mconcat (fmap f xs)
> Which is complaining about the line I highlighted above.  So I try:
> data Stream m a
> = Chunks (m a)
> | EOF
> deriving (Show, Eq)
> instance (Monad m, MonadPlus m, Monoid (m a)) => Monoid (Stream m a) where
> mempty = Chunks mempty
> mappend (Chunks xs) (Chunks ys) = Chunks (xs `mappend` ys)
> mappend _ _ = EOF
> instance (Monad m, MonadPlus m, Monoid (m a)) => Monad (Stream m) where
> return = Chunks . return
> Chunks xs >>= f = mconcat (fmap f xs)
> EOF >>= _ = EOF
> But the same trick doesn't work:
> Iteratee.hs:35:10:
>     Variable occurs more often in a constraint than in the instance head
>       in the constraint: Monoid (m a)
>     (Use -XUndecidableInstances to permit this)
>     In the instance declaration for `Monad (Stream m)'
> Is that because I don't use a on the right hand side of =>?
> Cheers,
> -John
> On 31 May 2011 15:54, Malcolm Wallace  wrote:
>>
>> instance (Monad m, MonadPlus m) => Monoid (Stream m a) where
>>
>> mempty = Chunks mempty
>> mappend (Chunks xs) (Chunks ys) = Chunks (xs `mappend` ys)
>> mappend _ _ = EOF
>>
>> Iteratee.hs:28:25:
>>     No instance for (Monoid (m a))
>>       arising from a use of `mempty'
>>
>> There is a clue in the first part of the error message.  Add the required
>> instance as part of the predicate:
>> instance (Monad m, MonadPlus m, Monoid (m a)) => Monoid (Stream m a) where
>> ...
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] What's the advantage of writing Haskell this way?

2011-05-30 Thread Lyndon Maydwell
I just tried to use the generic form with (Maybe a) and 'mconcat'
prevented this from working, so that needs to be considered too.

On Mon, May 30, 2011 at 10:53 PM, Casey McCann  wrote:
> On Mon, May 30, 2011 at 9:01 AM, John Ky  wrote:
>> instance Monoid (Stream a) where
>>     mempty = Chunks mempty
>>     mappend (Chunks xs) (Chunks ys) = Chunks (xs ++ ys)
>>     mappend _ _ = EOF
>>
>> I guess, it shows my lack of experience in Haskell, but my question is, why
>> is writing the code this way preferred over say writing it like this:
>
> I don't care for the inconsistency in this example, using both mempty
> and (++). Your version is at least consistent, but I'd actually prefer
> to use mappend instead of (++) here, because it makes it clear that
> this isn't actually defining a "new" Monoid instance, just translating
> an existing instance for the constructor parameter to work for the
> surrounding data type.
>
> - C.
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] What's the advantage of writing Haskell this way?

2011-05-30 Thread Lyndon Maydwell
Because they are more general functions that work on all monads rather
than just lists.

This allows Stream to be defined more flexibly.

On Mon, May 30, 2011 at 9:01 PM, John Ky  wrote:
> Hi all,
> I'm trying to learn about enumerators by reading this paper and came across
> some code on page 2 that I found hard to digest, but I think I finally got
> it:
>
> import Data.Monoid
> data Stream a
> = Chunks [a]
> | EOF
> deriving (Show, Eq)
> instance Monad Stream where
> return = Chunks . return
> Chunks xs >>= f = mconcat (fmap f xs)
> EOF >>= _ = EOF
> instance Monoid (Stream a) where
> mempty = Chunks mempty
> mappend (Chunks xs) (Chunks ys) = Chunks (xs ++ ys)
> mappend _ _ = EOF
>
> I guess, it shows my lack of experience in Haskell, but my question is, why
> is writing the code this way preferred over say writing it like this:
>
> import Data.Monoid
> data Stream a
> = Chunks [a]
> | EOF
> deriving (Show, Eq)
> instance Monad Stream where
> return x = Chunks [x]
> Chunks xs >>= f = mconcat (fmap f xs)
> EOF >>= _ = EOF
> instance Monoid (Stream a) where
> mempty = Chunks []
> mappend (Chunks xs) (Chunks ys) = Chunks (xs ++ ys)
> mappend _ _ = EOF
>
> Cheers,
> -John
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] For Project Euler #1 isn't it more efficient to generate just the numbers you need?

2011-05-06 Thread Lyndon Maydwell
If you're looking for efficiency, I believe you can actually do #1 in
constant time:


On Sat, May 7, 2011 at 7:31 AM,   wrote:
> -- Instead of this
> -- sumMultiples3or5 s = sum [x | x <- [3..s-1], x `mod` 3 == 0 || x `mod` 5
> == 0]
>
>
> -- Isn't this faster
>
> sumMultiples3or5 s = sum ([x | x <- [3,6..s-1]] `merge` [x | x <-
> [5,10..s-1]])
>
> merge xs [] = xs
> merge [] ys = ys
> merge txs@(x:xs) tys@(y:ys)
>    | x < y     = x : xs `merge` tys
>    | x > y     = y : txs `merge` ys
>    | otherwise = x : xs `merge` ys
>
>
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Division: Is there a way to simultaneously find the quotient and remainder?

2011-05-06 Thread Lyndon Maydwell
Hoogle is very useful for the kinds of questions where you can
estimate a likely type:

http://www.haskell.org/hoogle/?hoogle=Integral+a+%3D%3E+a+-%3E+a+-%3E+%28a%2Ca%29

On Sat, May 7, 2011 at 12:50 AM, Chris Smith  wrote:
> Sure... see quotRem in the prelude.
>
> On May 6, 2011 10:49 AM,  wrote:
>> :)
>>
>>
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] 64 bit generic link warning on every compile

2011-04-15 Thread Lyndon Maydwell
I get this too.

I've heard that it is resolved in 7.0.3 but I can't recall where.

(System Version: Mac OS X 10.6.7 (10J869), The Glorious Glasgow
Haskell Compilation System, version 7.0.2)

On Sat, Apr 16, 2011 at 10:47 AM, Andrew Pennebaker
 wrote:
> GHC 7 compiles fine, but there's an additional warning during linking.
> $ system_profiler SPSoftwareDataType | grep "System Version"
>       System Version: Mac OS X 10.6.7 (10J869)
> $ ghc --version
> The Glorious Glasgow Haskell Compilation System, version 7.0.2
> $ cat hello.hs
> #!/usr/bin/env runhaskell
> module Main where
> main :: IO ()
> main = putStrLn "Hello World"
> $ ghc --make hello.hs
> [1 of 1] Compiling Main             ( hello.hs, hello.o )
> Linking hello ...
> ld: warning: -read_only_relocs cannot be used with x86_64
> $ ./hello
> Hello World
> Cheers,
> Andrew Pennebaker
> www.yellosoft.us
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Is there a way to find out the type inferred for a local function inside another function? :)

2011-04-08 Thread Lyndon Maydwell
Agda's concept of holes seems perfect for this. Does Haskell have
anything similar?

On Fri, Apr 8, 2011 at 9:50 PM, Kazu Yamamoto  wrote:
> I made a mistake. Use M-t instead of C-cC-t.
>
>>> Currently what I do is declare a signature for helper, and then if it
>>> gets a type error try to figure out how to fix it.  It's usually not
>>> very hard, but it would be slick to have the signature filled in
>>> automatically.
>>
>> Try ghc-mod on Hackage if you are an Emacs user.
>>
>> If GHC can guess the signature of helper function, haskell-mode with
>> ghc-mod automatically hilights the function. Typing C-cC-t inserts the
>> guessed signature.
>>
>>       http://www.mew.org/~kazu/proj/ghc-mod/en/
>>
>> --Kazu
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Setting up cabal on EC2

2011-04-02 Thread Lyndon Maydwell
Many thanks to the Cabal devs :-)

On Sat, Apr 2, 2011 at 7:12 PM, Daniel Fischer
 wrote:
> On Saturday 02 April 2011 11:51:03, Lyndon Maydwell wrote:
>> The version of cabal-install on this page seems to be out of date:
>> http://www.haskell.org/cabal/download.html
>
> So-so. Probably the majority of users are still on ghc-6.*, for them, 0.8.2
> is the right choice. The page should have two links, one for ghc-6 and one
> for ghc-7, but I guess the Cabal cabal is too busy doing more important
> things (like writing code) to always think of updating the web-page.
>
>>
>> Luckily the other releases are listed at
>> http://www.haskell.org/cabal/release.
>>
>> This seems to have solved my issue.
>
> Good.
> Just a tip, generally, it's easier to get stuff from hackage,
> http://hackage.haskell.org/package/cabal-install
> in this case.
> You can see the dependencies listed there, and see what version fits best
> with what you have. If something depends on an older version of a library
> than you have, that's a bad sign. If something depends on a newer version
> of time, process, directory, random (a couple of others, basically what ghc
> itself was built with), that's a bad sign too.
> When in doubt,
> $ cabal install whatever --dry-run
> If that says it would install a library you already have, be careful, that
> may introduce the dreaded diamond dependency problem.
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Setting up cabal on EC2

2011-04-02 Thread Lyndon Maydwell
Thanks Daniel!

The version of cabal-install on this page seems to be out of date:
http://www.haskell.org/cabal/download.html

Luckily the other releases are listed at http://www.haskell.org/cabal/release.

This seems to have solved my issue.

On Sat, Apr 2, 2011 at 5:21 PM, Daniel Fischer
 wrote:
> On Saturday 02 April 2011 11:10:42, Lyndon Maydwell wrote:
>> Hi all.
>>
>> I'm having some issues setting up cabal on EC2.
>>
>> I've installed ghc 7.0.2, however, the bootstrap.sh script for
>>
>> cabal-install is complaining about missing dependencies:
>> > Linking Setup ...
>> > Configuring Cabal-1.8.0.2...
>
> That looks wrong. ghc-7 comes with Cabal-1.10, so you should better build
> cabal-install with that, that would be cabal-install-0.10.
> Which cabal-install package have you?
>
>> > Setup: At least the following dependencies are missing:
>> > base >=4 && <3 && >=1 && <5, filepath >=1 && <1.2
>
> That's a weird constraint. Impossible to fulfill, >= 4 && < 3.
>
>> > Setup: At least the following dependencies are missing: base >=4 && <3
>> > && >=1 && <5, filepath >=1 && <1.2
>>
>> ghc-pkg tells me that I have base and filepath installed:
>> > /usr/local/lib/ghc-7.0.2/package.conf.d
>> >
>> >    base-4.3.1.0
>> >
>> > /usr/local/lib/ghc-7.0.2/package.conf.d
>> >
>> >    filepath-1.2.0.0
>>
>> Could there be an environment variable I need to set somewhere?
>
> Try downloading and unpacking cabal-install-0.10.* and run the bootstrap
> script from that. If that doesn't work, report again.
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Setting up cabal on EC2

2011-04-02 Thread Lyndon Maydwell
Hi all.

I'm having some issues setting up cabal on EC2.

I've installed ghc 7.0.2, however, the bootstrap.sh script for
cabal-install is complaining about missing dependencies:

> Linking Setup ...
> Configuring Cabal-1.8.0.2...
> Setup: At least the following dependencies are missing:
> base >=4 && <3 && >=1 && <5, filepath >=1 && <1.2
> Setup: At least the following dependencies are missing: base >=4 && <3 && >=1 
> && <5, filepath >=1 && <1.2

ghc-pkg tells me that I have base and filepath installed:

> /usr/local/lib/ghc-7.0.2/package.conf.d
>base-4.3.1.0

> /usr/local/lib/ghc-7.0.2/package.conf.d
>filepath-1.2.0.0

Could there be an environment variable I need to set somewhere?

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] object oriented technique

2011-03-29 Thread Lyndon Maydwell
Should that be inner :: s?


> data Shape = forall s. (Shapeful s)
>   => Shape { sx, sy :: Double,
>  inner  :: a }
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Anyone recommend a VPS?

2011-03-19 Thread Lyndon Maydwell
Does anyone have any Binaries that are built to run on EC2?

That would be super!

On Tue, Feb 2, 2010 at 1:11 AM, Jason Dusek  wrote:
> 2010/01/31 Marc Weber :
>> If all you want is standard debian or such it does'nt matter.
>> However I tried installing NixOS Linux and I've had lot's of
>> trouble until switching to linode. NixOS was up and running
>> within 30min then..
>
>  How did you get NixOS on your Linode system? They don't seem to
>  offer it, last I checked.
>
>  I'm looking in to doing this with PRGMR, which has pretty good
>  pricing though it's not nearly as featureful as Linode.
>
> --
> Jason Dusek
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Convert a function to a string of operators?

2011-03-10 Thread Lyndon Maydwell
> Will methods explained here work for boolean expressions?

The convenience of defining using specialised datatypes for
serialising numeric operations comes from Num being a typeclass. This
is not the case for Bool:

Prelude> :info Num
class (Eq a, Show a) => Num a where
  (+) :: a -> a -> a
   ... -- Defined in GHC.Num

Prelude> :info Bool
data Bool = False | True-- Defined in GHC.Bool

> Is there a way to extract parameter names from function definition to
> use them in Show instance? Or should I just use same names everywhere?

The only kind of introspection I know comes from Template Haskell, but
I'm sure there are other methods that I'm not aware of available.

On Sun, Mar 6, 2011 at 7:28 AM, Evgeny Grablyk  wrote:
> Many thanks for your help! Seems to be what I need. Two more related 
> questions:
>
> Will methods explained here work for boolean expressions?
> Is there a way to extract parameter names from function definition to
> use them in Show instance? Or should I just use same names everywhere?
>
> In case  that helps, here's the code I need to convert (the code in
> where part of solveScheme): http://npaste.de/aKY3cn0xZf/
>
> --
> Evgeny
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell GUI

2011-02-16 Thread Lyndon Maydwell
That's true, but I've not had any luck with any other GUI libraries :(

On Wed, Feb 16, 2011 at 9:35 PM, Felipe Almeida Lessa
 wrote:
> On Wed, Feb 16, 2011 at 11:26 AM, Lyndon Maydwell  wrote:
>> OpenGL + GLUT has always been very reliable for me.
>
> I don't think this OpenGL + GLUT combination works well for user
> interfaces in the sense that you have to build everything from the
> ground up.
>
> Cheers!
>
> --
> Felipe.
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell GUI

2011-02-16 Thread Lyndon Maydwell
OpenGL + GLUT has always been very reliable for me.

On Wed, Feb 16, 2011 at 5:11 PM, Heinrich Apfelmus
 wrote:
> Chris Smith wrote:
>>
>> Mihai Maruseac wrote:
>>>
>>> Right now, I am unsure on what is best to use. Can someone give me any
>>> hints on which is the most kept-to-date and most supported GUI
>>> library?
>>
>> It would be hard to beat Gtk2Hs if you're looking for mature, solid, up
>> to date, and widely used.  Gtk2Hs isn't particularly functional in
>> style, but as imperative approaches go, it is probably the most widely
>> used general purpose GUI toolkit in the Haskell community, and very good
>> quality.
>
> I never managed to get a proper installation of GTK+ and Gtk2HS on my MacOS
> X machine. WxHaskell works fine, though.
>
>
> Regards,
> Heinrich Apfelmus
>
> --
> http://apfelmus.nfshost.com
>
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANN: FunGEn-0.3 simple 2D game engine released

2011-02-13 Thread Lyndon Maydwell
I've never used darcsden before. I take it your username is simon?

On Mon, Feb 14, 2011 at 5:43 AM, Simon Michael  wrote:
>>> Would it be worth re-exporting a type-aliased GLdouble to completely
>>> hide the implementation?
>
> PS, and now I understand more clearly - yes, you're quite right. I meant to
> do that.
>
> Perhaps some day it could use a graphics-and-IO abstraction layer (like
> HaskGame).
>
>
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANN: FunGEn-0.3 simple 2D game engine released

2011-02-13 Thread Lyndon Maydwell
Wow.

I've been working almost exclusively with GLUT because it seems to be
the only multi-platform graphics toolkit that works for me. This looks
great! It certainly seems to take the pain out of texture-loading
which always drives me up the wall.

The examples seem to be loading OpenGL in order to access GLdouble.
Apart from this there seem to be no underlying libraries exposed.
Would it be worth re-exporting a type-aliased GLdouble to completely
hide the implementation?

I will definitely play with this some more :)

On Mon, Feb 14, 2011 at 4:33 AM, Simon Michael  wrote:
> All - inspired by #haskell-game, I'm pleased to announce that FunGEn has
> been revived as a community project. This makes Andre Furtado's 2002 work
> available to the new generation of haskell game developers. :)
>
> FunGEn (Functional Game Engine) is a platform-independent, BSD-licensed,
> easy-to-install 2D game engine currently based on OpenGL and GLUT. As of
> 2011 it is the only general-purpose game engine, and the easiest way to
> throw together simple 2D games, in Haskell. On the downside, I'm told GLUT
> can't handle simultaneous keypresses, but the included examples are quite
> playable.
>
> If Andre reads this and would like to get involved, or send corrections to
> my doc updates, that would be great. In any case, I hope to see your forks
> and patches making this better. This is also a chance to test darcsden.com's
> ability to serve as a lighter github.
>
> Release: http://hackage.haskell.org/package/FunGEn
> Code and docs: http://darcsden.com/simon/fungen
> Original home, more docs:  http://www.cin.ufpe.br/~haskell/fungen
>
> Best,
> -Simon
>
>
> On Feb 10, 2011, at 12:40 PM, Simon Michael wrote:
>
>> Hi Andre, wman.. you guys haven't been responding, but FYI #haskell-game
>> IRC channel has been revived and I have just been updating FunGEn's status
>> on the wiki a bit:
>>
>>
>> http://www.haskell.org/haskellwiki/Applications_and_libraries/Games#Game_Engines_and_Libraries
>>
>> http://www.haskell.org/haskellwiki/Game_Development
>>
>> If you're available/interested to join us on the channel, or update the
>> hackage package, you'd be welcome! Otherwise perhaps we'll take a shot at it
>> some time in future.
>>
>> Best,
>> -Simon
>
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Why is there no "splitSeperator" function in Data.List

2011-02-13 Thread Lyndon Maydwell
Does the Python implementation operate on Strings, or all lists?

I think this could be quite important as many split implementations
take regular expressions as arguments. This could be quite challenging
for general lists.

That said, I would like to see some of these features in the split package.

On Sun, Feb 13, 2011 at 5:50 PM, Iustin Pop  wrote:
> On Sat, Feb 12, 2011 at 11:21:37AM -0500, Gwern Branwen wrote:
>> On Sat, Feb 12, 2011 at 11:00 AM, Robert Clausecker  wrote:
>> > Is there any reason, that one can't find a function that splits a list
>> > at a seperator in the standard library? I imagined something like this:
>> >
>> >
>> >    splitSeperator :: Eq a => a -> [a] -> [[a]]
>> >
>> >    splitSeperator ',' "foo,bar,baz"
>> >      --> ["foo","bar","baz"]
>> >
>> > Or something similar? This is needed so often, even if I can implement
>> > it in one line, is there any reason why it's not in the libs?
>>
>> See http://hackage.haskell.org/package/split
>>
>> The reason it's not in Data.List is because there are a bazillion
>> different splits one might want (when I was pondering the issue before
>> Brent released it, I had collected something like 8 different proposed
>> splits), so no agreement could ever be reached.
>
> It is curious though that the Python community managed to agree on a
> single implementation and include that in the standard library… So it is
> possible :)
>
> I also needed a split function and ended up with coding one that behaves
> like the Python one for my project.
>
> regards,
> iustin
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Interactive OpenGL-based graphics and ghci?

2010-11-20 Thread Lyndon Maydwell
I've always had issues with GLUT under ghci. If GHC 7 fixes this it
will make me happy :)

On Sun, Nov 21, 2010 at 7:54 AM, Luke Palmer  wrote:
> On Sat, Nov 20, 2010 at 4:46 PM, Conal Elliott  wrote:
>> I'm trying to find some way to do interactive, OpenGL-based graphics in
>> Haskell on Mac OS X.
>> Does anyone here use GLUT or SDL on Mac OS X with ghci, or maybe an
>> alternative library?
>
> I was reading the GHC 7 release notes and saw this:
>
> * There is a new -fno-ghci-sandbox flag, which stops GHCi running
> computations in a separate thread; in particular, this works around an
> issue running GLUT from GHCi on OS X
>
> So that seems to indicate that GLUT would fulfill your needs.
>
> Luke
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] New .hs File Icons

2010-09-04 Thread Lyndon Maydwell
This looks great!

On Fri, Sep 3, 2010 at 4:59 PM, Christian Eltges  wrote:
> Hello,
>
> I was wondering why the File-Icon installed by GHC with the lambda for
> .hs files hasn't changed to the new
> bind+lambda icon used on haskel.org.
> Is this because it should be the same as the icon used by hugs?
> I've created a new icon myself, which I use on my pc (using the svg
> file from the haskell wiki).
> So if the only reason for using the old icon was, that there is no new
> one, then you can use this.
>
> Best regards
>
> Christian
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Quick Question for QuickCheck2

2010-08-31 Thread Lyndon Maydwell
$HOME/.cabal/bin

On Wed, Sep 1, 2010 at 10:55 AM, Ivan Lazar Miljenovic
 wrote:
> Do you have ~/.cabal/bin or $HOME/.cabal/bin ?  The latter is
> preferable as some issues arise with the former...
>
> On 1 September 2010 03:29, Lyndon Maydwell  wrote:
>> Yep :)
>>
>> Is there a batch of information that might be useful? I can send any
>> relevant files, aliases, versions, etc at once to help if you like.
>>
>> On Wed, Sep 1, 2010 at 12:35 AM, Sebastian Höhn
>>  wrote:
>>>
>>> Do you have ~/.cabal/bin/ in your PATH?
>>>
>>> - Sebastian
>>>
>>> Am 31.08.2010 um 15:57 schrieb Lyndon Maydwell:
>>>
>>>> Yep. Definitely the same user.
>>>>
>>>> On Tue, Aug 31, 2010 at 7:35 PM, Ivan Lazar Miljenovic
>>>>  wrote:
>>>>> On 31 August 2010 20:38, Lyndon Maydwell  wrote:
>>>>>> ghc-pkg check doesn't list any broken dependencies.
>>>>>
>>>>> You sure this is with the same user?  ghci is unlikely to complain
>>>>> about broken libraries if ghc-pkg check doesn't...
>>>>>
>>>>> --
>>>>> Ivan Lazar Miljenovic
>>>>> ivan.miljeno...@gmail.com
>>>>> IvanMiljenovic.wordpress.com
>>>>>
>>>> ___
>>>> Haskell-Cafe mailing list
>>>> Haskell-Cafe@haskell.org
>>>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>>
>>> ___
>>> Haskell-Cafe mailing list
>>> Haskell-Cafe@haskell.org
>>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>>
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>
>
>
> --
> Ivan Lazar Miljenovic
> ivan.miljeno...@gmail.com
> IvanMiljenovic.wordpress.com
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Quick Question for QuickCheck2

2010-08-31 Thread Lyndon Maydwell
Yep :)

Is there a batch of information that might be useful? I can send any
relevant files, aliases, versions, etc at once to help if you like.

On Wed, Sep 1, 2010 at 12:35 AM, Sebastian Höhn
 wrote:
>
> Do you have ~/.cabal/bin/ in your PATH?
>
> - Sebastian
>
> Am 31.08.2010 um 15:57 schrieb Lyndon Maydwell:
>
>> Yep. Definitely the same user.
>>
>> On Tue, Aug 31, 2010 at 7:35 PM, Ivan Lazar Miljenovic
>>  wrote:
>>> On 31 August 2010 20:38, Lyndon Maydwell  wrote:
>>>> ghc-pkg check doesn't list any broken dependencies.
>>>
>>> You sure this is with the same user?  ghci is unlikely to complain
>>> about broken libraries if ghc-pkg check doesn't...
>>>
>>> --
>>> Ivan Lazar Miljenovic
>>> ivan.miljeno...@gmail.com
>>> IvanMiljenovic.wordpress.com
>>>
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Quick Question for QuickCheck2

2010-08-31 Thread Lyndon Maydwell
Yep. Definitely the same user.

On Tue, Aug 31, 2010 at 7:35 PM, Ivan Lazar Miljenovic
 wrote:
> On 31 August 2010 20:38, Lyndon Maydwell  wrote:
>> ghc-pkg check doesn't list any broken dependencies.
>
> You sure this is with the same user?  ghci is unlikely to complain
> about broken libraries if ghc-pkg check doesn't...
>
> --
> Ivan Lazar Miljenovic
> ivan.miljeno...@gmail.com
> IvanMiljenovic.wordpress.com
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Quick Question for QuickCheck2

2010-08-31 Thread Lyndon Maydwell
ghc-pkg check doesn't list any broken dependencies.

On Tue, Aug 31, 2010 at 9:27 AM, Ivan Lazar Miljenovic
 wrote:
> On 31 August 2010 03:18, Lyndon Maydwell  wrote:
>> Thanks!
>>
>> This makes perfect sense, but as I just discovered using ghci -v there
>> is an even stranger problem. I'm side-tracking slightly from the
>> original question here, but nevertheless...
>>
>> GHC gives the following output:
>>
>> ---
>> GHCi, version 6.12.3: http://www.haskell.org/ghc/  :? for help
>> : cannot satisfy -package QuickCheck-2.1.1.1:
>>    QuickCheck-2.1.1.1-c7435cb0d5b5de72fe9540c48335606d is unusable
>> due to missing or recursive dependencies:
>>      ghc-6.12.3-66a382195c8a71849653439b67021fd1
>>    (use -v for more information)
>>
>> shell returned 1
>
> What does "ghc-pkg check" say?
>
> To me, it sounds like you upgraded a boot library, which is a big no-no.
>
> (The ghc mentioned here is the ghc library, not the compiler itself.)
>
> --
> Ivan Lazar Miljenovic
> ivan.miljeno...@gmail.com
> IvanMiljenovic.wordpress.com
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Quick Question for QuickCheck2

2010-08-30 Thread Lyndon Maydwell
Thanks!

This makes perfect sense, but as I just discovered using ghci -v there
is an even stranger problem. I'm side-tracking slightly from the
original question here, but nevertheless...

GHC gives the following output:

---
GHCi, version 6.12.3: http://www.haskell.org/ghc/  :? for help
: cannot satisfy -package QuickCheck-2.1.1.1:
QuickCheck-2.1.1.1-c7435cb0d5b5de72fe9540c48335606d is unusable
due to missing or recursive dependencies:
  ghc-6.12.3-66a382195c8a71849653439b67021fd1
(use -v for more information)

shell returned 1
---

However I am using the version of GHC mentioned, so I have no idea
what is going on.


On Tue, Aug 31, 2010 at 1:09 AM, John Millikin  wrote:
> Update your cabal package list, and then install QuickCheck.
> Optionally, you can use a version specifier:
>
>    cabal update
>    cabal install 'QuickCheck >= 2'
>
> This should make QuickCheck 2 the default in GHCI. If it doesn't, you
> may need to specify the version:
>
>    ghci -package QuickCheck-2.2
>
> For Cabal-packaged libraries/applications, simply update your version
> requirements.
>
>
> On Mon, Aug 30, 2010 at 09:06, Lyndon Maydwell  wrote:
>> I'm just trying these examples, and I can't figure out how to import
>> quickcheck2 rather than quickcheck1. I've looked around but I can't
>> seem to find any information on this. How do I do it?
>>
>> Thanks!
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Quick Question for QuickCheck2

2010-08-30 Thread Lyndon Maydwell
I'm just trying these examples, and I can't figure out how to import
quickcheck2 rather than quickcheck1. I've looked around but I can't
seem to find any information on this. How do I do it?

Thanks!

On Mon, Aug 30, 2010 at 11:56 PM, John Millikin  wrote:
> Define a custom element generator, which has characters with your
> desired values:
>
> myRange :: Gen Char
> myRange = elements (['A'..'Z'] ++ ['a' .. 'z'] ++ " ~...@#$%^&*()")
>
> You can use "forAll" to run tests with a specific generator:
>
> forAll myRange $ \c -> chr (ord c) == c
>
> On Mon, Aug 30, 2010 at 08:12, Sebastian Höhn
>  wrote:
>> Hello,
>>
>> perhaps I am just blind or is it a difficult issue: I would like to
>> generate Char values in a given Range for QuickCheck2. There is this
>> simple example from the haskell book:
>>
>> instance Arbitrary Char where
>>   arbitrary = elements (['A'..'Z'] ++ ['a' .. 'z'] ++ " ~...@#$%^&*()")
>>
>> This does not work in QuickCheck2 since the instance is already
>> defined. How do I achieve this behaviour in QC2?
>>
>> Thanks for helping.
>>
>> Sebastian
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Compiled OpenGL program has DOS window?

2010-08-13 Thread Lyndon Maydwell
I vaguely recall that there is a way to avoid this if you don't import
any terminal functions or something similar. I don't remember the
specifics though.

Sorry I couldn't be of more help!



On Fri, Aug 13, 2010 at 4:18 PM, Eitan Goldshtrom
 wrote:
> Hi. I'm working in Windows on an OpenGL application. I finally got
> everything working, doing all of my testing through the interpreter. When I
> finally compiled and ran the program from an executable for the first time I
> noticed that before creating my OpenGL window an empty DOS prompt popped up.
> I think I understand why the computer would want to do that, but I don't
> know how to make it stop. I've done some OpenGL in C++ and I remember having
> a similar problem. If I remember correctly the problem was fixed with a
> compiler flag. I'm using GHC and I looked through their compiler flags, but
> I didn't find anything that looked like it would deal with this. Anyone have
> any ideas?
>
> -Eitan
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ghc in macports

2010-08-11 Thread Lyndon Maydwell
Seconded.

I've started using the Haskell Platform mainly because the ports
version is out of date.

Unfortunately it keeps getting pulled in as a dependency of something
even though I'm not using it.

On Wed, Aug 11, 2010 at 10:49 PM, Ozgur Akgun  wrote:
> Dear Cafe,
>
> I wonder who is maintaining the ghc package in macports, and what the
> current stategy of doing things is?
> http://www.macports.org/ports.php?by=name&substr=ghc (ghc 6.10.4)
>
> Personally, I'd like to use the macports version, if the ghc version there
> was resonably recent (having 2 versions, a stable and an edge could be a
> good idea?)
>
> Thanks,
> Ozgur
>
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Unused import warnings.

2010-08-10 Thread Lyndon Maydwell
Fantastic. It was the bug mentioned.

On Wed, Aug 11, 2010 at 5:00 AM, Martijn van Steenbergen
 wrote:
> Are you saying that GHC complains about an unused import that is in fact
> used? Perhaps you've run into this bug:
> http://hackage.haskell.org/trac/ghc/ticket/1148
>
> Are you using a recent version of GHC?
>
> Groetjes,
>
> Martijn.
>
>
> On 8/10/10 22:22, Lyndon Maydwell wrote:
>>
>> Hi Cafe.
>>
>> I have written some QuickCheck properties in my source and am using
>> these for testing, however, when I compile my program I get warned
>> about unused imports:
>>
>>> Warning: Module `Test.QuickCheck' is imported, but nothing from it is
>>> used
>>
>> Is there a way to suppress these warnings for a particular module by
>> using a pragma directive or something similar?
>>
>>
>> Thanks!
>>
>> - Lyndon
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Unused import warnings.

2010-08-10 Thread Lyndon Maydwell
Is there a way to just ignore the warnings for QuickCheck?

On Wed, Aug 11, 2010 at 4:32 AM, Christopher Done
 wrote:
> On 10 August 2010 22:25, Lyndon Maydwell  wrote:
>> On Wed, Aug 11, 2010 at 4:23 AM, Christopher Done
>>  wrote:
>>> On 10 August 2010 22:22, Lyndon Maydwell  wrote:
>>>> Hi Cafe.
>>>>
>>>> I have written some QuickCheck properties in my source and am using
>>>> these for testing, however, when I compile my program I get warned
>>>> about unused imports:
>>>>
>>>>> Warning: Module `Test.QuickCheck' is imported, but nothing from it is used
>>>>
>>>> Is there a way to suppress these warnings for a particular module by
>>>> using a pragma directive or something similar?
>>>
>>> You can do:
>>>
>>> import Test.QuickCheck ()
>>>
>> I'm using qualified properties with (import Test.QuickCheck ((==>)))
>> so that may not be possible.
>
> Ah, ok. In that case you can use -fno-warn-unused-imports. You can
> pass that to GHC, or put it in as an OPTIONS pragma:
>
> {-# OPTIONS -fno-warn-unused-imports #-}
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Unused import warnings.

2010-08-10 Thread Lyndon Maydwell
I'm using qualified properties with (import Test.QuickCheck ((==>)))
so that may not be possible.

On Wed, Aug 11, 2010 at 4:23 AM, Christopher Done
 wrote:
> On 10 August 2010 22:22, Lyndon Maydwell  wrote:
>> Hi Cafe.
>>
>> I have written some QuickCheck properties in my source and am using
>> these for testing, however, when I compile my program I get warned
>> about unused imports:
>>
>>> Warning: Module `Test.QuickCheck' is imported, but nothing from it is used
>>
>> Is there a way to suppress these warnings for a particular module by
>> using a pragma directive or something similar?
>
> You can do:
>
> import Test.QuickCheck ()
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Unused import warnings.

2010-08-10 Thread Lyndon Maydwell
Hi Cafe.

I have written some QuickCheck properties in my source and am using
these for testing, however, when I compile my program I get warned
about unused imports:

> Warning: Module `Test.QuickCheck' is imported, but nothing from it is used

Is there a way to suppress these warnings for a particular module by
using a pragma directive or something similar?


Thanks!

- Lyndon
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: [web-devel] statically compiled css

2010-08-08 Thread Lyndon Maydwell
Sassy?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Can we come out of a monad?

2010-08-01 Thread Lyndon Maydwell
That's true I suppose, although since there are no implicit parameters
in haskell, it really has to be a DSL in implementation, rather than
just theory right?

On Mon, Aug 2, 2010 at 12:51 PM, Ivan Miljenovic
 wrote:
> On 2 August 2010 14:47, Lyndon Maydwell  wrote:
>> I thought it was pure as, conceptually, readFile isn't 'run' rather it
>> constructs a pure function that accepts a unique world state as a
>> parameter. This might be totally unrealistic, but this is how I see IO
>> functions remaining pure. Is this a good mental model?
>
> That is what I believe Ertugrul is aiming at, but I believe that that
> is a "rule-lawyering" interpretation in trying to argue that all of
> Haskell is pure.  We could use this same argument to state that _all_
> programming languages are pure, as they too have implict "World" state
> variables that get passed around.
>
> --
> Ivan Lazar Miljenovic
> ivan.miljeno...@gmail.com
> IvanMiljenovic.wordpress.com
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Can we come out of a monad?

2010-08-01 Thread Lyndon Maydwell
I thought it was pure as, conceptually, readFile isn't 'run' rather it
constructs a pure function that accepts a unique world state as a
parameter. This might be totally unrealistic, but this is how I see IO
functions remaining pure. Is this a good mental model?


> In terms of what a function does, is readFile actually pure?
>
> --
> Ivan Lazar Miljenovic
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Can we come out of a monad?

2010-07-29 Thread Lyndon Maydwell
You cannot break out of a monad if all you have available to use are
the monad typeclass functions, however there is nothing preventing an
instance from being created that allows escape. Many of these escape
methods come in the form of runX functions, but you can use
constructors to break out with pattern matching if they are exposed.

As far as I can tell, IO is more of an outlier in this regard.

(Did I miss something?)

On Fri, Jul 30, 2010 at 2:23 PM, C K Kashyap  wrote:
> Hi,
> In the code here -
> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=28393#a28393
> If I look at the type of modifiedImage, its simply ByteString - but isn't it
> actually getting into and back out of the state monad? I am of the
> understanding that once you into a monad, you cant get out of it? Is this
> breaking the "monad" scheme?
> --
> Regards,
> Kashyap
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Random this! ;-)

2010-07-26 Thread Lyndon Maydwell
I find it useful to have a seed argument to nearly all random
functions rather than using ones with an IO signature. This way you
can speed up your program quite a bit and also make testing much
easier. I think that MonadRandom does this automatically too.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Huffman Codes in Haskell

2010-06-23 Thread Lyndon Maydwell
I made (presumably) inefficient huffman algorithm not too long ago:

http://www.hpaste.org/fastcgi/hpaste.fcgi/view?id=26484#a26484

I guess it doesn't normally need to be terribly efficient as the
result can be stored in a map of some sort.

On Wed, Jun 23, 2010 at 10:41 PM, John Lato  wrote:
>> From: Max Rabkin 
>>
>> This seems like an example of list-chauvinism -- what Chris Okasaki
>> calls a communal blind spot of the FP community in Breadth-First
>> Numbering: Lessons from a Small Exercise in Algorithm Design --
>> http://www.eecs.usma.edu/webs/people/okasaki/icfp00.ps
>>
>
> Thanks for sharing; this was an interesting (and short!) read.
>
> I would like to see other Haskeller's responses to this problem.  I'll
> restate it here hoping to get replies from those who haven't read the
> paper yet:
>
> Assume you have a type of labeled binary trees:
>
> data Tree a = E | T a (Tree a) (Tree a)
>
> and you are to produce a function
>
> bfnum :: Tree a -> Tree Int
>
> that performs a breadth-first numbering of the tree (starting with 1),
> preserving the tree structure.
>
> How would you implement bfnum?  (If you've already read the paper,
> what was your first answer?)
>
> For the record, my solution doesn't rely on any other data structures
> or laziness AFAICT, and I think it would fit into the Level-Oriented
> category of solutions.
>
> John
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: [Haskell-beginners] Accounting Engine in Haskell

2010-06-15 Thread Lyndon Maydwell
I don't think I can be of much help with regards to the questions, but
would you be able to post a link to the SPJ lecture?

Thanks :-)

On Tue, Jun 15, 2010 at 4:08 PM, Amiruddin Nagri  wrote:
>
> My current project is about making an accounting engine that handles all
> the journal entries, transactions, portfolios etc. The communication
> with the engine is based on simple protocol, the things to be taken
> care of in the order are consistency, handling large data(performance) and
> availability.
>
> I came across a video lecture by Simon Peyton Jones where he gives an
> example from Financial domain (derivatives etc) to explain how haskell is
> being used and the advantages provided.
>
> I am interested in knowing if Haskell will be the right fit for my project.
> My requirements are transactional nature, which I believe is one of the
> strengths of functional programming, also handling large data set and being
> available. there is no such requirement for partitioning of data and the
> application is going to be centrally hosted on a single server.
>
> AFAIK OCaml and other functional languages are heavily used in financial
> domain, some of the reason are same as features I am looking for.
> I wanted some insight as to how Haskell is going to help me with my project.
> Also there has been some concerns because of lazy evaluation in Haskell and
> memory leaks associated with it.
> http://jlouisramblings.blogspot.com/2010/04/haskell-vs-erlang-for-bittorent-clients.html
>
> Also, if you have any suggestions of the choice of programming
> language, we have been looking into other functional languages like
>  Scala and Clojure. But we have not dig deep on the performance
> aspects of these languages, if someone can shed a light on the pros-
> cons of these languages, it will help us very much to come to a
> decision.
>
> -Regards,
> Amir
>
> ___
> Beginners mailing list
> beginn...@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Work on Video Games in Haskell

2010-05-26 Thread Lyndon Maydwell
This sounds fantastic. Now I wish I had started learning haskell a few
years earlier.

As a side note, how is this project getting around the language
restrictions apple put in the developer license agreement?

--- [http://daringfireball.net/2010/04/iphone_agreement_bans_flash_compiler]
In the new version of the iPhone Developer Program License Agreement
released by Apple today (and which developers must agree to before
downloading the 4.0 SDK beta), section 3.3.1 now reads:

3.3.1 — Applications may only use Documented APIs in the manner
prescribed by Apple and must not use or call any private APIs.
Applications must be originally written in Objective-C, C, C++, or
JavaScript as executed by the iPhone OS WebKit engine, and only code
written in C, C++, and Objective-C may compile and directly link
against the Documented APIs (e.g., Applications that link to
Documented APIs through an intermediary translation or compatibility
layer or tool are prohibited).
---

On Wed, May 26, 2010 at 2:52 PM, Ryan Trinkle
 wrote:
> iPwn Studios is seeking Haskell developers for its debut title, BloodKnight.
> * No prior game development experience is required, but you must be very
> comfortable working in Haskell.
> * Compensation is negotiable; profit-sharing may be available in some cases.
> * To apply, or for more information, contact me at r...@ipwnstudios.com.
> BloodKnight is an action-roleplaying game inspired by games like Diablo and
> Fallout.  It is currently in the final stages of development, and will be
> released later this year on a variety of smartphone platforms, including
> iPhone and Android.
> iPwn Studios is a start-up company located in Boston, MA.  We believe in
> giving back to the Haskell community, so we've open-sourced our ghc-iphone
> project, which allows GHC to produce binaries for the iPhone.  Check it out
> at http://projects.haskell.org/ghc-iphone/.
>
> Ryan Trinkle
> iPwn Studios
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Hackage accounts and real names

2010-04-05 Thread Lyndon Maydwell
I hardly think you can say that _why had a negative impact on the ruby
community...

On Tue, Apr 6, 2010 at 9:53 AM, Christopher Done
 wrote:
> On 6 April 2010 01:52, Ivan Miljenovic  wrote:
>> On 6 April 2010 10:48, Christopher Done  wrote:
>>> This discussion makes me ponder whether someone like _why the lucky
>>> stiff would ever contribute Haskell packages, hehe.
>>
>> I think we can do without someone who hides behind anonymity and then
>> suddenly decides to go and delete all of their work when they've had
>> enough.
>
> Yes, pseudonymous people tend to delete all their work, and
> non-anonymous people are incapable of deleting all their work.
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Hackage accounts and real names

2010-04-05 Thread Lyndon Maydwell
How would enforcing a 'real names' policy affect a contributor like
_why (http://en.wikipedia.org/wiki/Why_the_lucky_stiff)? I assume they
would not join the community.

I get the feeling that this discussion is somehow linked to haskell's
type-system, but have no idea why...
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Graphical representation of Haskell code

2010-03-22 Thread Lyndon Maydwell
Reminds me of To Dissect a Mockingbird [http://dkeenan.com/Lambda/].

On Tue, Mar 23, 2010 at 7:12 AM, Ivan Miljenovic
 wrote:
> On 23 March 2010 10:02, Dupont Corentin  wrote:
>> I’m relatively new to Haskell.
>
> Welcome!
>
>> I’m wondering if it exist a tool to graphically represent Haskell code.
>>
>> Look at the little graphics at: http://www.haskell.org/arrows/index.html 
>> (and following pages) from Ross Paterson.
>>
>> If found these very useful to understand the Arrow monad.
>>
>> Why not automatise this in a tool? Such a tool could draw a graphic from the 
>> code of a program.
>
> 1) Because no-one has written such a tool yet (though someone has
> suggested doing one as a GSoC project).
> 2) I'm of the opinion that unless you just use it on small snippets,
> the generated images will be too large and unweildy.
>
>> This could be done entirely automatically from the types of the functions.
>
> Except not everyone provides type signatures for their functions;
> whilst it may be possible to use the GHC API to infer these type
> signatures, my understanding is that it's preferable to use other
> parsers such as haskell-src-exts as the GHC API is unstable.
>
> [shameless plug]
> My SourceGraph (http://hackage.haskell.org/package/SourceGraph) tool
> does function call visualisation as part of its analyses.
> [/shameless plug]
>
>
> --
> Ivan Lazar Miljenovic
> ivan.miljeno...@gmail.com
> IvanMiljenovic.wordpress.com
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Abstraction in data types

2010-03-17 Thread Lyndon Maydwell
Well you need to define a new datatype to make a hertrogenous list, so
I don't think there's any real way you can get around people doing
that...

On Thu, Mar 18, 2010 at 1:27 PM, Darrin Chandler
 wrote:
> On Thu, Mar 18, 2010 at 01:06:25PM +0800, Lyndon Maydwell wrote:
>> You could probably also use a typeclass for pointy things rather than
>> a data type, this would then require you to use existential
>> quantification to construct a hetrogenous list.
>>
>> For example:
>>
>> Class Point where
>>     getCartesian :: ...
>>     getPolar :: ...
>>
>> data Shape = Point p => ... | Polygon [p]
>>
>> Correct me if this is wrong though :-)
>
> So in "normal" use Polygon list would be homogeneous, but could be made
> heterogeneous with effort? If I have that right it's closer, but I'd
> love to have the compiler whine if someone tried to mix them.
>
>> On Thu, Mar 18, 2010 at 12:56 PM, Alexander Solla  wrote:
>> > I wrote this to Darrin, but didn't CC cafe:
>> > On Mar 17, 2010, at 9:20 PM, Darrin Chandler wrote:
>> >
>> > type Cartesian_coord = Float
>> >
>> > type Latitude  = Float
>> > type Longitude = Float
>> >
>> > data Point = Cartesian (Cartesian_coord, Cartesian_coord)
>> > | Spherical (Latitude, Longitude)
>> >
>> > type Center = Point
>> > type Radius = Float
>> >
>> > data Shape = Circle Center Radius
>> > | Polygon [Point]
>> >
>> > This obviously stinks since a Polygon could contain mixed Cartesian and
>> > Spherical points. Polygon needs to be one or the other, but not mixed.
>> >
>> > My suggestion would be to use an alternate representation of "spherical"
>> > points in terms of polar coordinates, and then to normalize and mix at 
>> > will:
>> > type Theta = Float
>> > type Radius = Float
>> > data Point = Cartesian (Cartesian_coord, Cartesian_coord)
>> >            | Polar   (Theta, Radius)
>> > normalize_point :: Point -> Point
>> > normalize_point Cartesian x y = Cartesian x y
>> > normalize_point Polar t r = Cartesian x y where x = r * cos t; y = r * sin
>> > t;
>> > It really depends on what you want to do with your points.  If you want to
>> > do linear algebra, you might want your points to depend on a basis, for
>> > example.  But your "spherical" points don't really form a basis in
>> > three-space, or even over all of two-space.
>> > ___
>> > Haskell-Cafe mailing list
>> > Haskell-Cafe@haskell.org
>> > http://www.haskell.org/mailman/listinfo/haskell-cafe
>> >
>> >
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>
> --
> Darrin Chandler            |  Phoenix BSD User Group  |  MetaBUG
> dwchand...@stilyagin.com   |  http://phxbug.org/      |  http://metabug.org/
> http://www.stilyagin.com/  |  Daemons in the Desert   |  Global BUG Federation
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Abstraction in data types

2010-03-17 Thread Lyndon Maydwell
You could probably also use a typeclass for pointy things rather than
a data type, this would then require you to use existential
quantification to construct a hetrogenous list.

For example:

Class Point where
getCartesian :: ...
getPolar :: ...

data Shape = Point p => ... | Polygon [p]

Correct me if this is wrong though :-)

On Thu, Mar 18, 2010 at 12:56 PM, Alexander Solla  wrote:
> I wrote this to Darrin, but didn't CC cafe:
> On Mar 17, 2010, at 9:20 PM, Darrin Chandler wrote:
>
> type Cartesian_coord = Float
>
> type Latitude  = Float
> type Longitude = Float
>
> data Point = Cartesian (Cartesian_coord, Cartesian_coord)
> | Spherical (Latitude, Longitude)
>
> type Center = Point
> type Radius = Float
>
> data Shape = Circle Center Radius
> | Polygon [Point]
>
> This obviously stinks since a Polygon could contain mixed Cartesian and
> Spherical points. Polygon needs to be one or the other, but not mixed.
>
> My suggestion would be to use an alternate representation of "spherical"
> points in terms of polar coordinates, and then to normalize and mix at will:
> type Theta = Float
> type Radius = Float
> data Point = Cartesian (Cartesian_coord, Cartesian_coord)
>            | Polar   (Theta, Radius)
> normalize_point :: Point -> Point
> normalize_point Cartesian x y = Cartesian x y
> normalize_point Polar t r = Cartesian x y where x = r * cos t; y = r * sin
> t;
> It really depends on what you want to do with your points.  If you want to
> do linear algebra, you might want your points to depend on a basis, for
> example.  But your "spherical" points don't really form a basis in
> three-space, or even over all of two-space.
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Game of life in haskell.

2010-02-02 Thread Lyndon Maydwell
Thanks for the replies.

I have heard of Hash Life, but I thought I'd try a more naive approach
first, build up some type-classes, then create some more interesting
implementations (although I think I'd struggle with implementing Hash
Life in haskell at this point).

> What is the meaning of fuzzy Game of Life? Where can I read about?

I don't think there are any official rules for fuzzy Life, and it
would really be a different automaton, but you can still get some of
the same Life phenomenon occurring in it. It gets mentioned reasonably
often and shows up if you google for it. (For example:
http://cogprints.org/1479/0/life.html)

I'd like to create something of a cellular-automaton engine with a
fair degree of flexibility (2d/3d, boolean/fuzzy/other, different
neighborhoods). It could make a fairly nice screen-saver if it were
polished, but I can't really see any applications beyond that.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Game of life in haskell.

2010-02-02 Thread Lyndon Maydwell
I'm avoiding hard-coding bools anywhere as I intend to allow
fuzzy-representations at some point.

On Wed, Feb 3, 2010 at 12:10 AM, Serguey Zefirov  wrote:
> 2010/2/2 Lyndon Maydwell :
>> I chose the array mainly for the fast lookup time compared to lists,
>> are you suggesting something like creating a "Map (X,Y) Health"? I'm
>> not currently updating any structures, rather creating the successor
>> from scratch. I can see how the map may work very well for the sparse
>> nature of non-early life games now that I think of it.
>
> Because your Health is basically Bool, you can use Set (X,Y) for a set
> of live objects.
>
> Creation of new Array is (without knowing some subtle details) is
> O(max coordinates difference between live cells). Creation of new Set
> (X,Y) is O(NlogN) (N = number of live objects). Most of the cells in
> Life are empty, so the Set/Map approach is faster. Also it leads to
> very concise code.
>
> Actually, your solution with arrays is the most often occured solution
> an imperative programmer will come with. It is simple but not scalable
> and not particularly fast.
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Game of life in haskell.

2010-02-02 Thread Lyndon Maydwell
I chose the array mainly for the fast lookup time compared to lists,
are you suggesting something like creating a "Map (X,Y) Health"? I'm
not currently updating any structures, rather creating the successor
from scratch. I can see how the map may work very well for the sparse
nature of non-early life games now that I think of it.

On Tue, Feb 2, 2010 at 11:48 PM, Serguey Zefirov  wrote:
> 2010/2/2 Lyndon Maydwell :
>> Hi Cafe.
>>
>> I've made a basic game of life implementation with Haskell and OpenGL:
>> https://github.com/sordina/Life/
>>
>> I'm intending to improve the performance, and add more advanced
>> features, but I thought I'd get some feedback first. Can anyone see a
>> way to make this code more idiomatic, or any optimizations I might
>> have missed?
>
> Arrays are not fully "idiomatic" for Haskell as they are hard to
> update functionally.
>
> Also, their use incurs quadratic update cost for simple scene with two
> gliders that fly in different directions.
>
> So I advice you to use Data.Map.Map and Data.Set.Set data structures.
>
> How? It's an easy question. ;)
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Game of life in haskell.

2010-02-02 Thread Lyndon Maydwell
Hi Cafe.

I've made a basic game of life implementation with Haskell and OpenGL:
https://github.com/sordina/Life/

The basic premise is to generate a random snapshot, then iterate the
successor function on it to create an infinite list of snapshots, then
output them using OpenGL. I haven't really run into any major issues
aside from not being able to figure out how to automatically rerun the
display function, however I believe this is an OpenGL problem, and not
related to the Haskell side (press 'n' to move to the next snapshot
for now).

To run the game: cabal configure && cabal build &&
./dist/build/life/life 

I'm intending to improve the performance, and add more advanced
features, but I thought I'd get some feedback first. Can anyone see a
way to make this code more idiomatic, or any optimizations I might
have missed?

I'm still fairly new to Haskell and I haven't really come to grips
with monad-transformers and the like yet, so if any advanced
techniques are applicable here it would really help me link what I
think I understand to reality :-)

Also, is something like this worth uploading to Hackage, or should I
leave it on github?

Thanks guys.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Trapping getChar before echo

2010-02-01 Thread Lyndon Maydwell
It might be worth looking at something like a curses library.

On Mon, Feb 1, 2010 at 4:45 PM, Mark Spezzano
 wrote:
> I've tried this example and it just lets me type in anything in CAPITALS, 
> which is nice, but Delete key doesn't delete and the arrow keys unfortunately 
> let me manoeuvre the cursor all over the screen. Also the biggest problem is 
> that Enter doesn't terminate the input session.
>
> Isn't there a simple way to do something like this?
>
> Surely Haskell must have a standard getLine function that support CAPITALS 
> and backspacing and no arrow keys. Arrows keys with history would be nice.
>
> Mark
>
>
> On 31/01/2010, at 11:27 PM, Andrew Coppin wrote:
>
>> Michael Hartl wrote:
>>> import System.IO
>>> import Data.Char
>>>
>>> main = do
>>>  hSetEcho stdin False
>>>  hSetBuffering stdin NoBuffering
>>>  hSetBuffering stdout NoBuffering
>>>  scanLine
>>>      where scanLine = do               c <- hGetChar stdin
>>>              putChar . toUpper $ c
>>>              scanLine
>>>
>>
>> Last time I tried something like this [on Windows], it didn't seem to work. 
>> I wanted to trap arrow keys and so forth, but they seem to be being used for 
>> input history. (I.e., pressing the up-arrow produces previously-entered 
>> lines of text, and none of this appears to be reaching the Haskell program 
>> itself.) Has this changed since I tried it last year?
>>
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>>
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: ghc: unrecognised flags: -I

2010-01-26 Thread Lyndon Maydwell
I found the problem.

I had an empty entry for extra library includes in my cabal
configuration. Once I commented this out things started working again.
I think that cabal should probably not include a lone -I in this case
though. Is there somewhere I can file a bug?

Thanks guys.

On Mon, Jan 25, 2010 at 4:58 PM, Christian Maeder
 wrote:
> Lyndon Maydwell schrieb:
>> For example, when I "cabal install -v storable-complex" I get the following:
>>
>> /usr/bin/ghc -package-name storable-complex-0.2.1 --make
>> -hide-all-packages -i -idist/build -i. -idist/build/autogen
>> -Idist/build/autogen -Idist/build -I -optP-include
>> -optPdist/build/autogen/cabal_macros.h -odir dist/build -hidir
>> dist/build -stubdir dist/build -package base-3.0.3.1 -O
>> Foreign.Storable.Complex
>> ghc: unrecognised flags: -I
>
> For me this works (and does not have that single "-I"):
>
> /home/mac-bkb/bin/ghc -package-name storable-complex-0.2.1 --make
> -hide-all-packages -i -idist/build -i. -idist/build/autogen
> -Idist/build/autogen -Idist/build -optP-include
> -optPdist/build/autogen/cabal_macros.h -odir dist/build -hidir
> dist/build -stubdir dist/build -package base-3.0.3.1 -O
> Foreign.Storable.Complex
>
>> Has anyone encountered this before, or more realistically, can anyone
>> give me some advice on how to narrow this problem down further?
>
> Sorry, no idea.
>
>> I'm running cabal version 1.6.0.1, ghc 6.10.4 on OS X 10.5.
>
> I've got Cabal-1.6.0.3, ghc 6.10.4 on OS X 10.5 (Intel)
>
> cabal-install version 0.6.2
> using version 1.6.0.3 of the Cabal library
>
> Christian
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] ghc: unrecognised flags: -I

2010-01-24 Thread Lyndon Maydwell
Hi Cafe!

That's a capital "i" for anyone with font issues.

I posted this question to beginners a while ago, but received no
meaningful response so I'm trying cafe instead :-)

Most packages I try to install off Hackage with cabal are giving me
the error "ghc: unrecognised flags: -I".

For example, when I "cabal install -v storable-complex" I get the following:

/usr/bin/ghc -package-name storable-complex-0.2.1 --make
-hide-all-packages -i -idist/build -i. -idist/build/autogen
-Idist/build/autogen -Idist/build -I -optP-include
-optPdist/build/autogen/cabal_macros.h -odir dist/build -hidir
dist/build -stubdir dist/build -package base-3.0.3.1 -O
Foreign.Storable.Complex
ghc: unrecognised flags: -I

I've updated everything several times since this error started
occurring, but it persists. I've tried digging to find out where the
lone -I is being injected but can't seem to track it down.

Has anyone encountered this before, or more realistically, can anyone
give me some advice on how to narrow this problem down further?

I'm running cabal version 1.6.0.1, ghc 6.10.4 on OS X 10.5.

Thanks guys!
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Lisp like symbols in haskell

2009-12-08 Thread Lyndon Maydwell
Aren't symbols made redundant by algebraic data types?

On Tue, Dec 8, 2009 at 4:48 PM, Michael Vanier  wrote:
> jean-christophe mincke wrote:
>>
>> Hello,
>>
>> Has there already been attempts to introduce lisp like symbols in haskell?
>>
>>
>> Thank you
>>
>> Regards
>>
>> J-C
>>
>
> J-C,
>
> Do you mean symbols as in "interned strings with an O(1) string comparison
> method"?  I would love to have those, but I don't see an easy way to get it
> without being in the IO or ST monad.
>
> Mike
>
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Hayoo and Hoogle (beginner question)

2009-12-07 Thread Lyndon Maydwell
I had heard that Hoogle actually compiled any type-signatures, where
as Hayoo just did a text comparison.

I'm not actually sure if this is true or not though.

If it is, it would mean that "[q] -> [r] -> [(q,r)]" would return zip
in Hoogle, but not Hayoo.

Am I right about this?

On Mon, Dec 7, 2009 at 4:52 PM, drostin77  wrote:
>
> I take 'Hood.  Er... any responses to my questions?
>
>
> Ketil Malde-5 wrote:
>>
>> Lyndon Maydwell  writes:
>>
>>> On Mon, Dec 7, 2009 at 2:43 PM, Colin Adams>
>>>  wrote:
>>
>>>> 2009/12/7 drostin77 :
>>
>>>>> Hello Hopefully Helpful Haskell Community!
>>
>>>>> (I really wanted that to be alliteration... couldn't come up with an h
>>>>> word
>>>>> for community)
>>
>>>> House?
>>
>>> 'Hood?
>>
>> Horde?  And of course, haskell.org is the Hopefully Helpful Haskell Hoard.
>>
>> -k
>> --
>> If I haven't seen further, it is by standing in the footprints of giants
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>>
>
> --
> View this message in context: 
> http://old.nabble.com/Hayoo-and-Hoogle-%28beginner-question%29-tp26669924p26674323.html
> Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Hayoo and Hoogle (beginner question)

2009-12-06 Thread Lyndon Maydwell
'Hood?

On Mon, Dec 7, 2009 at 2:43 PM, Colin Adams
 wrote:
> 2009/12/7 drostin77 :
>>
>> Hello Hopefully Helpful Haskell Community!
>>
>> (I really wanted that to be alliteration... couldn't come up with an h word
>> for community)
>
> House?
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] I miss OO

2009-11-25 Thread Lyndon Maydwell
You can define the methods with the same names in different modules,
then when you are importing them into the same module for use, use a
qualified import.

import qualified Dog
import qualified Tree

This will allow you to use exactly the syntax you described.

Dog.bark
Tree.bark

Plus if you only have to import one of these, it is an opportunity to
be implicit which about  the module being used.

On Thu, Nov 26, 2009 at 6:34 AM, pbrowne  wrote:
> Luke Palmer  wrote
>> I feel like this should be qualified.  Type classes are not for name
>> punning ; you wouldn't use a type class for the method bark on types
>> Tree and Dog.  But if you have a well-defined *structure* that many
>> types follow, then a type class is how you capture that.  It sounds
>> like you do have this structure in your example.
>
> Is there any way that type classes can manage name spaces to
> disambiguate functions like bark on types Tree and Dog?
>
> If constants are considered as unary functions, can we use constants in
> type classes and/or instances?  How are local class specific constants,
> such as tank in Army/tank in Fish, bank in River/bank in Finance, handled?
>
> Pat
>
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Exceptions during exception unwinding

2009-10-01 Thread Lyndon Maydwell
Exception handling code should generally be assumed to work, so if
something goes wrong there you would normally like to know about it.
Also, there is nothing preventing you from wrapping the rescue code in
further exception handling, however, if the initial error were raised
upon encountering a second error, you would not be able to choose to
handle the second error.

This is how I see it anyway.

On Thu, Oct 1, 2009 at 11:29 AM, Brian Bloniarz  wrote:
>
> I had a question about onException & friends: what's the rationale
> for having:
> (error "foo") `onException` (error "bar")
>
> give bar and not foo? I.e. why does an exception raised during
> exception handling get propagated past the exception that triggered
> the handler?
>
> Most examples I can think for exception unwinding code would prefer the
> original exception be propagated -- for example, HDBC has a function which
> rolls back a DB transaction on exception; it implements it like so:
>> withTransaction conn func =
>>   do r <- onException (func conn) doRollback
>>  commit conn
>>  return r
>>   where doRollback =
>> -- Discard any exception from (rollback conn) so original
>> -- exception can be re-raised
>> Control.Exception.catch (rollback conn) doRollbackHandler
>> doRollbackHandler :: SomeException -> IO ()
>> doRollbackHandler _ = return ()
> IMHO, it'd be easier to just write:
>> withTransaction conn func =
>>   do r <- onException (func conn) (rollback conn)
>>  commit conn
>>  return r
>
> This same argument applies to bracket, bracket_, bracketOnError & finally;
> even the common:
>> bracket openSomeHandle closeSomeHandle doAction
> If some error arises during doAction, there's a chance closeSomeHandle might 
> fail
> (even a good chance, given that exception unwinding paths are usually poorly
> tested), and probably doAction has more accurate information about what went
> wrong than closeSomeHandle.
>
> This is just a thought; I hadn't seen this discussed somewhere. I know for
> example that Java has the same approach as the current Control.Exception, so
> there must be good arguments for that too. One that I can think of: using
> onException to rethrow an exception as a different type, though that's what
> mapException is for, correct?
>
> Thanks,
> -Brian
> _
> Microsoft brings you a new way to search the web.  Try  Bing™ now
> http://www.bing.com?form=MFEHPG&publ=WLHMTAG&crea=TEXT_MFEHPG_Core_tagline_try
>  bing_1x1___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


  1   2   >