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: How to add a "method" to a record (martin)
----------------------------------------------------------------------
Message: 1
Date: Fri, 12 Sep 2014 19:05:11 +0200
From: martin <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] How to add a "method" to a record
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Am 09/10/2014 08:50 PM, schrieb Corentin Dupont:
> If the field "label" can be deduced from "payload", I recommend not to
> include it in your structure, because that would
> be redundant.
>
> Here how you could write it:
>
> data Foo pl = Foo { payload :: pl}
>
> labelInt :: Foo Int -> String
> labelInt (Foo a) = "Int payload:" ++ (show a)
>
> labelString :: Foo String -> String
> labelString (Foo a) = "String payload" ++ a
>
> You are obliged to define two separate label function, because "Foo Int" and
> "Foo String" are two completly separate types.
This is exactly my problem: Someone will use this type an define the type of
pl. How can I know what type she'll use?
What I'd like to express is that whoever creates a concrete type should also
provide the proper label function.
>
> On Wed, Sep 10, 2014 at 2:06 PM, martin <[email protected]>
> wrote:
>
> Hello all
>
> if I have a record like
>
> data Foo pl = Foo {
> label :: String,
> payload :: pl
> }
>
> how can I create a similar type where I can populate label so it
> is not a plain string, but a function which
> operates on
> payload? Something like
>
> label (Foo pl) = show pl
>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 75, Issue 9
****************************************