<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Ok, I got it now.  I was misunderstanding how the REPL was interacting with the IO Monad.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">I had once tried<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">do { g <- newStdGen; take 10 $ randomRs (1,6) g  }<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">but I actually needed this<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">do { g <- newStdGen; return . take 10 $ randomRs (1,6) g  }<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Thanks,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Jeff<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri","sans-serif"">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri","sans-serif""> Beginners [mailto:beginners-bounces@haskell.org]
<b>On Behalf Of </b>David McBride<br>
<b>Sent:</b> Monday, September 15, 2014 7:27 PM<br>
<b>To:</b> The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell<br>
<b>Subject:</b> Re: [Haskell-beginners] ghci and randomRs<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">The simple answer is with do notation:<o:p></o:p></p>
</div>
<p class="MsoNormal">main = do<o:p></o:p></p>
</div>
<p class="MsoNormal">  g <- newStdGen<o:p></o:p></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt">  print $ randomRs (1,2) g<o:p></o:p></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt">Or without do notation, something like:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">newStdGen >>= print . take 10 . randomRs (1,2)<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Mon, Sep 15, 2014 at 10:01 PM, Jeff C. Britton <<a href="mailto:jcb@iteris.com" target="_blank">jcb@iteris.com</a>> wrote:<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">I am trying to use randomRs at the ghci prompt like so<br>
<br>
Prelude System.Random> take 10 $ (randomRs (1, 6) newStdGen)<br>
<br>
but I get the following error<br>
<interactive>:16:12:<br>
    Could not deduce (RandomGen (IO StdGen))<br>
      arising from a use of `randomRs'<br>
    from the context (Random a, Num a)<br>
      bound by the inferred type of it :: (Random a, Num a) => [a]<br>
      at <interactive>:16:1-37<br>
    In the second argument of `($)', namely<br>
      `(randomRs (1, 6) newStdGen)'<br>
    In the expression: take 10 $ (randomRs (1, 6) newStdGen)<br>
    In an equation for `it': it = take 10 $ (randomRs (1, 6) newStdGen)<br>
<br>
<br>
I have tried a variety of options, like wrapping it in a "do" or adding type annotations.<br>
Nothing seems to work.<br>
<br>
<br>
<br>
-----Original Message-----<br>
From: Beginners [mailto:<a href="mailto:beginners-bounces@haskell.org">beginners-bounces@haskell.org</a>] On Behalf Of martin<br>
Sent: Friday, September 12, 2014 10:05 AM<br>
To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell<br>
Subject: Re: [Haskell-beginners] How to add a "method" to a record<br>
<br>
Am 09/10/2014 08:50 PM, schrieb Corentin Dupont:<br>
> If the field "label" can be deduced from "payload", I recommend not to<br>
> include it in your structure, because that would be redundant.<br>
><br>
> Here how you could write it:<br>
><br>
> data Foo pl = Foo { payload :: pl}<br>
><br>
> labelInt :: Foo Int -> String<br>
> labelInt (Foo a) = "Int payload:" ++ (show a)<br>
><br>
> labelString :: Foo String -> String<br>
> labelString (Foo a) = "String payload" ++ a<br>
><br>
> You are obliged to define two separate label function, because "Foo Int" and "Foo String" are two completly separate types.<br>
<br>
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?<br>
What I'd like to express is that whoever creates a concrete type should also provide the proper label function.<br>
<br>
><br>
>         On Wed, Sep 10, 2014 at 2:06 PM, martin <<a href="mailto:martin.drautzburg@web.de">martin.drautzburg@web.de</a>> wrote:<br>
><br>
>             Hello all<br>
><br>
>             if I have a record like<br>
><br>
>                     data Foo pl = Foo {<br>
>                                 label :: String,<br>
>                                 payload :: pl<br>
>                             }<br>
><br>
>             how can I create a similar type where I can populate label so it is not a plain string, but a function which<br>
>             operates on<br>
>             payload? Something like<br>
><br>
>                     label (Foo pl) = show pl<br>
><br>
<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><o:p></o:p></p>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</body>
</html>