Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: Looking for a datastructure (David Place)
2. Can fields in a record be optional? (Costello, Roger L.)
3. Re: Can fields in a record be optional? (David Place)
4. cabal install reactive-banana-wx (Tom Murphy)
5. Re: cabal install reactive-banana-wx (Arlen Cuss)
6. Re: Can fields in a record be optional? (Christopher Done)
7. Re: Can fields in a record be optional? (David Virebayre)
8. Re: cabal install reactive-banana-wx (Stephen Tetley)
9. Re: Can fields in a record be optional? (Yitzchak Gale)
10. Re: Can fields in a record be optional? (Yitzchak Gale)
11. Re: Can fields in a record be optional? (Michael Snoyman)
----------------------------------------------------------------------
Message: 1
Date: Sun, 17 Jul 2011 10:09:48 -0400
From: David Place <[email protected]>
Subject: Re: [Haskell-beginners] Looking for a datastructure
To: "[email protected] Beginer" <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Jul 17, 2011, at 3:57 AM, Kees Bleijenberg wrote:
> 2. A fast way to find the key with the lowest map-value (without traversing
> the whole map).
I see. If you were to implement it without worrying about the performance,
you could just use a map and compute a fold over the map to find the min value.
To have better performance, you want to incrementally recompute the fold at
each update. This is the topic of an article that I wrote for the Monad.Reader
called "How to refold a map."
> http://www.haskell.org/wikiupload/6/6a/TMR-Issue11.pdf
I show how to modify Data.Map for that purpose. Also, it turns out to be
really nice to implement it in FingerTrees. If you would like I can post that
too.
___________________
David Place
Owner, Panpipes Ho! LLC
http://panpipesho.com
[email protected]
------------------------------
Message: 2
Date: Sun, 17 Jul 2011 18:03:08 -0400
From: "Costello, Roger L." <[email protected]>
Subject: [Haskell-beginners] Can fields in a record be optional?
To: "[email protected]" <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="us-ascii"
Hi Folks,
Can fields in a record be made "optional"?
Let me motivate my question:
I have a data type called "Contract". It is a record. It has one field that
holds a currency value, a second field that holds payments, and a third field
to hold sub-Contracts.
data Contract = Contract {
currency :: Currency
, payments :: Double
, contracts :: [Contract]
}
deriving (Show)
Here is a function that creates a Contract with currency c and payments = 1:
one :: Currency -> Contract
one c = Contract { currency = c, payments = 1, contracts = [] }
Since there are no sub-Contracts I'd rather not specify that last field.
Here is a function that AND's two Contracts, c1 and c2, and returns one
Contract:
and :: Contract -> Contract -> Contract
(and) c1 c2 = Contract { currency = undefined, payments = undefined,
contracts = [c1, c2] }
I'd rather not specify those first two fields.
See why I desire optional fields?
Perhaps I am going about it completely wrong and there is a better way to
express Contract? I am eager to learn!
/Roger
------------------------------
Message: 3
Date: Sun, 17 Jul 2011 18:18:55 -0400
From: David Place <[email protected]>
Subject: Re: [Haskell-beginners] Can fields in a record be optional?
To: "Costello, Roger L." <[email protected]>
Cc: "[email protected]" <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
The way I often do this is to create an "ur" instance where all the fields have
default values. Then to create an instance, I just do a "record update" of
this instance. For example:
data Contract = Contract {
currency :: Currency
, payments :: Double
, contracts :: [Contract]
}
deriving (Show)
urContract = Contract { currency = undefined, payments = undefined, contracts =
[] }
one :: Currency -> Contract
one c = urContract { currency = c, payments = 1}
and :: Contract -> Contract -> Contract
(and) c1 c2 = urContract { contracts = [c1, c2] }
____________________
David Place
Owner, Panpipes Ho! LLC
http://panpipesho.com
[email protected]
On Jul 17, 2011, at 6:03 PM, Costello, Roger L. wrote:
> Hi Folks,
>
> Can fields in a record be made "optional"?
>
------------------------------
Message: 4
Date: Sun, 17 Jul 2011 21:00:25 -0400
From: Tom Murphy <[email protected]>
Subject: [Haskell-beginners] cabal install reactive-banana-wx
To: beginners <[email protected]>
Message-ID:
<cao9q0tu9s_mxwmvyzuen8_wha7zwlfyqj-w5d0eseb08icd...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Install troubles! (Is the right place for this type of message?)
Thanks!
Tom
$ cabal install reactive-banana-wx
Resolving dependencies...
cabal: cannot configure wxdirect-0.12.1.3. It requires containers >=0.2 &&
<0.4
For the dependency on containers >=0.2 && <0.4 there are these packages:
containers-0.2.0.0, containers-0.2.0.1 and containers-0.3.0.0. However none of
them are available.
containers-0.2.0.0 was excluded because containers-0.4.0.0 was selected
instead
containers-0.2.0.0 was excluded because reactive-banana-0.4.1.0 requires
containers ==0.4.*
containers-0.2.0.1 was excluded because containers-0.4.0.0 was selected
instead
containers-0.2.0.1 was excluded because reactive-banana-0.4.1.0 requires
containers ==0.4.*
containers-0.3.0.0 was excluded because containers-0.4.0.0 was selected
instead
containers-0.3.0.0 was excluded because reactive-banana-0.4.1.0 requires
containers ==0.4.*
------------------------------
Message: 5
Date: Mon, 18 Jul 2011 11:23:01 +1000
From: Arlen Cuss <[email protected]>
Subject: Re: [Haskell-beginners] cabal install reactive-banana-wx
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
18/07/2011 11:00 AM, Tom Murphy kirjutas:
> Install troubles! (Is the right place for this type of message?)
I'm not 100% sure, but you might more likely reach the person
responsible (or knowledgable, as the case may be) on haskell-cafe.
------------------------------
Message: 6
Date: Mon, 18 Jul 2011 07:45:29 +0200
From: Christopher Done <[email protected]>
Subject: Re: [Haskell-beginners] Can fields in a record be optional?
To: David Place <[email protected]>
Cc: "[email protected]" <[email protected]>
Message-ID:
<caajhnpdtbrbp4+vr5h5almpuhh+qpmb__hzuvtleepadyrm...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
On 18 July 2011 00:18, David Place <[email protected]> wrote:
> The way I often do this is to create an "ur" instance where all the fields
> have default values. ?Then to create an instance, I just do a "record update"
> of this instance.
For this there is Data.Default in data-default:
http://hackage.haskell.org/packages/archive/data-default/0.2.0.1/doc/html/Data-Default.html
------------------------------
Message: 7
Date: Mon, 18 Jul 2011 08:20:24 +0200
From: David Virebayre <[email protected]>
Subject: Re: [Haskell-beginners] Can fields in a record be optional?
To: "Costello, Roger L." <[email protected]>
Cc: "[email protected]" <[email protected]>
Message-ID:
<CAM_wFVuXTXXiZ368EeMpf=jq40ong8ujkgenpylldgyv-um...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
I'm not sure I would model your datatype this way, I don't like the
idea to put unnecessary undefined values in the case of subcontracts.
I would instead
data Contract = Contract { currency :: Currency, payments :: Double }
| SubContract { contracts :: [Contract] }
one c = Contract { currency = c, payments = 1 }
and :: Contract -> Contract -> Contract
(and) c1 c2 = Subcontract { contracts = [c1, c2] }
------------------------------
Message: 8
Date: Mon, 18 Jul 2011 07:43:50 +0100
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] cabal install reactive-banana-wx
Cc: beginners <[email protected]>
Message-ID:
<CAB2TPRD7RE78iF7e+nQOt9YifvHVAd_9AAsFM=hymay0u4t...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Try installing either installing wxDirect 0.12.1.4; or wxDirect
012.1.3 with the build option "splitBase" first.
There's a difference in the cabal files between 0.12.1.3 and 0.12.1.4
where the file defaults to container Base 3.0 and Containers 0.3
(wxDirect 0.12.1.3) or Base 4.0 and Containers 0.4 (wxDirect
0.12.1.4).
Latest GHC versions have Base 4.0 and Containers 0.4, wxDirect
0.12.1.4 should work by default for latest GHC versions. wxDirect
0.12.1.3 needs building with the "splitBase" flag passed to work with
latest GHCs.
On 18 July 2011 02:00, Tom Murphy <[email protected]> wrote:
> Install troubles! (Is the right place for this type of message?)
...
> $ cabal install reactive-banana-wx
> Resolving dependencies...
> cabal: cannot configure wxdirect-0.12.1.3. It requires containers >=0.2 &&
> <0.4
> For the dependency on containers >=0.2 && <0.4 there are these packages:
> containers-0.2.0.0, containers-0.2.0.1 and containers-0.3.0.0. However none of
> them are available.
> containers-0.2.0.0 was excluded because containers-0.4.0.0 was selected
> instead
[snip]
------------------------------
Message: 9
Date: Mon, 18 Jul 2011 09:44:26 +0300
From: Yitzchak Gale <[email protected]>
Subject: Re: [Haskell-beginners] Can fields in a record be optional?
To: [email protected]
Cc: "[email protected]" <[email protected]>
Message-ID:
<caorualaxcw0qm7eivvwjsnautaes6bqzm_8ae-tp37slu8d...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Christopher Done wrote:
> For this there is Data.Default in data-default:
> http://hackage.haskell.org/packages/archive/data-default/0.2.0.1/doc/html/Data-Default.html
You don't need the added complexity of a type class for
this - just define the default value.
The case where you need a class for default values is when you're using
generics. See, for example, System.Console.CmdArgs.Default in
Neil Mitchell's cmdards package[1].
Regards,
Yitz
[1] http://hackage.haskell.org/package/cmdargs
------------------------------
Message: 10
Date: Mon, 18 Jul 2011 09:51:28 +0300
From: Yitzchak Gale <[email protected]>
Subject: Re: [Haskell-beginners] Can fields in a record be optional?
To: [email protected]
Cc: "[email protected]" <[email protected]>
Message-ID:
<caorualychbr95ipc+m_u4y8wam4kejzhkg-kpvmj7tl+skm...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Oops, sorry about the typo. It's the *cmdargs* package.
http://hackage.haskell.org/package/cmdargs
-Yitz
------------------------------
Message: 11
Date: Mon, 18 Jul 2011 09:52:38 +0300
From: Michael Snoyman <[email protected]>
Subject: Re: [Haskell-beginners] Can fields in a record be optional?
To: [email protected]
Cc: "[email protected]" <[email protected]>
Message-ID:
<caka2jgl6zi24y+iakqrjpqxekud9j_mv6iw7pwux_ut28da...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
On Mon, Jul 18, 2011 at 9:44 AM, Yitzchak Gale <[email protected]> wrote:
> Christopher Done wrote:
>> For this there is Data.Default in data-default:
>> http://hackage.haskell.org/packages/archive/data-default/0.2.0.1/doc/html/Data-Default.html
>
> You don't need the added complexity of a type class for
> this - just define the default value.
I don't think it's a case of necessity. It just happens to be very
convenient to be able to use the three letters "def" instead of
"defaultFrobnicatorSettings" or something like that.
Michael
> The case where you need a class for default values is when you're using
> generics. See, for example, System.Console.CmdArgs.Default in
> Neil Mitchell's cmdards package[1].
>
> Regards,
> Yitz
>
> [1] http://hackage.haskell.org/package/cmdargs
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 37, Issue 31
*****************************************