Re: [Haskell-cafe] List Monads and non-determinism

2013-07-19 Thread Matt Ford
Hi, Thanks all for your good help. I was caught up in sequential thinking about monads so much so that I treated the lambda expressions as separate functions rather than a nested big one. That clears up a lot of nagging doubts. Cheers, Matt. On 20 Jul 2013, at 00:18, Rogan Creswick wro

Re: [Haskell-cafe] Dynamic and equality

2013-07-19 Thread Carter Schonwald
the tricky part then is to add support for other types. another approach to existentially package type classes with the data type! eg data HasEq = forall a . HasEq ( Eq a => a) or its siblinng data HasEq a = Haseq (Eq a => a ) note this requires more planning in how you structure your program,

Re: [Haskell-cafe] Wrapping all fields of a data type in e.g. Maybe

2013-07-19 Thread Michael Orlitzky
On 07/16/2013 04:57 PM, Michael Orlitzky wrote: > > This all works great, except that when there's 20 or so options, I > duplicate a ton of code in the definition of OptionalCfg. Is there some > pre-existing solution that will let me take a Cfg and create a new type > with Cfg's fields wrapped in

Re: [Haskell-cafe] List Monads and non-determinism

2013-07-19 Thread Timon Gehr
On 07/20/2013 12:58 AM, Matt Ford wrote: Hi, Thanks for the help. I thought >>= was left associative? It seems to be in the examples from Learn You A Haskell. ... Yes, >>= is left-associative. The associativity of >>= is not relevant for your example because no two >>= operations actually o

Re: [Haskell-cafe] List Monads and non-determinism

2013-07-19 Thread Chris Wong
> I thought >>= was left associative? It seems to be in the examples from > Learn You A Haskell. It is. But lambdas are parsed using the "maximal munch" rule, so they extend *as far to the right as possible*. So \x -> x * 2 + 1 would be parsed as \x -> (x * 2 + 1) -- right not

Re: [Haskell-cafe] List Monads and non-determinism

2013-07-19 Thread Rogan Creswick
On Fri, Jul 19, 2013 at 3:58 PM, Matt Ford wrote: > Hi, > > Thanks for the help. > > I thought >>= was left associative? It seems to be in the examples from > Learn You A Haskell. > > I tried to use the associative law to bracket from the right but it didn't > like that either... > > [1,2] >>= (

Re: [Haskell-cafe] List Monads and non-determinism

2013-07-19 Thread Matt Ford
Hi, Thanks for the help. I thought >>= was left associative? It seems to be in the examples from Learn You A Haskell. I tried to use the associative law to bracket from the right but it didn't like that either... [1,2] >>= (\x -> (\n -> [3,4])) x >>= \m -> return (n,m)) Any thoughts? Matt

Re: [Haskell-cafe] List Monads and non-determinism

2013-07-19 Thread Timon Gehr
On 07/20/2013 12:23 AM, Matt Ford wrote: Hi All, I thought I'd have a go at destructing [1,2] >>= \n -> [3,4] >>= \m -> return (n,m) which results in [(1,3)(1,4),(2,3),(2,4)] I started by putting brackets in ([1,2] >>= \n -> [3,4]) >>= \m -> return (n,m) ... This is not the same expression

Re: [Haskell-cafe] List Monads and non-determinism

2013-07-19 Thread Rogan Creswick
On Fri, Jul 19, 2013 at 3:23 PM, Matt Ford wrote: > I started by putting brackets in > > ([1,2] >>= \n -> [3,4]) >>= \m -> return (n,m) > > This immediately fails when evaluated: I expect it's something to do > with the n value now not being seen by the final return. > You're bracketing from the

[Haskell-cafe] List Monads and non-determinism

2013-07-19 Thread Matt Ford
Hi All, I thought I'd have a go at destructing [1,2] >>= \n -> [3,4] >>= \m -> return (n,m) which results in [(1,3)(1,4),(2,3),(2,4)] I started by putting brackets in ([1,2] >>= \n -> [3,4]) >>= \m -> return (n,m) This immediately fails when evaluated: I expect it's something to do with the n

Re: [Haskell-cafe] Dynamic and equality

2013-07-19 Thread adam vogt
On Fri, Jul 19, 2013 at 5:19 AM, Jose A. Lopes wrote: > Hello, > > How to define equality for Data.Dynamic ? Hi Jose, You could try casting the values to different types that do have an (==). You can treat the case where you have the types matching, but didn't list that type beforehand different

Re: [Haskell-cafe] Generating Haskell Code out of Haskell AST (GHC API)

2013-07-19 Thread Joachim Breitner
Hi, Am Freitag, den 19.07.2013, 11:19 +0200 schrieb John Blackbox: > The question about generating the code was only to have a "debugging > tool" - to see if the generated AST is good - I wanted to generate the > Haskell code only to check if its correct, but normally I would not do > it, because

Re: [Haskell-cafe] Generating Haskell Code out of Haskell AST (GHC API)

2013-07-19 Thread Daniel Trstenjak
Hi John, > Alan - I do NOT want to generate Haskell code. I want only to generate AST > and compile it. > The question about generating the code was only to have a "debugging tool" > - to see if the generated AST is good - I wanted to generate the Haskell > code only to check if its correct, but

Re: [Haskell-cafe] Generating Haskell Code out of Haskell AST (GHC API)

2013-07-19 Thread John Blackbox
I accidentally didn't send that email to haskell-cafe, so I'm pasting it here also: Alan - I do NOT want to generate Haskell code. I want only to generate AST and compile it. The question about generating the code was only to have a "debugging tool" - to see if the generated AST is good - I wanted

Re: [Haskell-cafe] Generating Haskell Code out of Haskell AST (GHC API)

2013-07-19 Thread John Blackbox
Thank you! So, if I'm writing a compiler of custom language, which I want to generate Haskell AST and further compile it with GHC, you prefer something like haskell-src-exts over pure GHC API? 2013/7/19 Antoine Latter > The package haskell-src-exts is a lot less intimidating if all you are > tr