<div dir="ltr"><div><div><div><div><div>The simple answer is with do notation:<br><br></div>main = do<br></div>  g <- newStdGen<br></div>  print $ randomRs (1,2) g<br><br></div>Or without do notation, something like:<br><br></div><div>newStdGen >>= print . take 10 . randomRs (1,2)<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Sep 15, 2014 at 10:01 PM, Jeff C. Britton <span dir="ltr"><<a href="mailto:jcb@iteris.com" target="_blank">jcb@iteris.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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><br>
</blockquote></div><br></div>