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.  ghci and randomRs (Jeff C. Britton)
   2. Re:  ghci and randomRs (Brandon Allbery)
   3. Re:  ghci and randomRs (David McBride)


----------------------------------------------------------------------

Message: 1
Date: Tue, 16 Sep 2014 02:01:30 +0000
From: "Jeff C. Britton" <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] ghci and randomRs
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="us-ascii"

I am trying to use randomRs at the ghci prompt like so

Prelude System.Random> take 10 $ (randomRs (1, 6) newStdGen)

but I get the following error
<interactive>:16:12:
    Could not deduce (RandomGen (IO StdGen))
      arising from a use of `randomRs'
    from the context (Random a, Num a)
      bound by the inferred type of it :: (Random a, Num a) => [a]
      at <interactive>:16:1-37
    In the second argument of `($)', namely
      `(randomRs (1, 6) newStdGen)'
    In the expression: take 10 $ (randomRs (1, 6) newStdGen)
    In an equation for `it': it = take 10 $ (randomRs (1, 6) newStdGen)


I have tried a variety of options, like wrapping it in a "do" or adding type 
annotations.
Nothing seems to work.



-----Original Message-----
From: Beginners [mailto:[email protected]] On Behalf Of martin
Sent: Friday, September 12, 2014 10:05 AM
To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level 
topics related to Haskell
Subject: Re: [Haskell-beginners] How to add a "method" to a record

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
> 

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


------------------------------

Message: 2
Date: Mon, 15 Sep 2014 22:05:52 -0400
From: Brandon Allbery <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] ghci and randomRs
Message-ID:
        <cakfcl4xvyx_ppgakyqb47zrn8ydkxagkhpmugvsc6ykge_5...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Mon, Sep 15, 2014 at 10:01 PM, Jeff C. Britton <[email protected]> wrote:

> Prelude System.Random> take 10 $ (randomRs (1, 6) newStdGen)


I think you need to read http://www.vex.net/~trebla/haskell/IO.xhtml.
You're trying to operate directly on an IO "program" (newStdGen) as if it
were a value.

-- 
brandon s allbery kf8nh                               sine nomine associates
[email protected]                                  [email protected]
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140915/9c1e0cd1/attachment-0001.html>

------------------------------

Message: 3
Date: Mon, 15 Sep 2014 22:27:02 -0400
From: David McBride <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] ghci and randomRs
Message-ID:
        <CAN+Tr41=8h2pdJOBzePv+XjGHyw-FE5TgMMrB+DFwcfZ6dr=v...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

The simple answer is with do notation:

main = do
  g <- newStdGen
  print $ randomRs (1,2) g

Or without do notation, something like:

newStdGen >>= print . take 10 . randomRs (1,2)

On Mon, Sep 15, 2014 at 10:01 PM, Jeff C. Britton <[email protected]> wrote:

> I am trying to use randomRs at the ghci prompt like so
>
> Prelude System.Random> take 10 $ (randomRs (1, 6) newStdGen)
>
> but I get the following error
> <interactive>:16:12:
>     Could not deduce (RandomGen (IO StdGen))
>       arising from a use of `randomRs'
>     from the context (Random a, Num a)
>       bound by the inferred type of it :: (Random a, Num a) => [a]
>       at <interactive>:16:1-37
>     In the second argument of `($)', namely
>       `(randomRs (1, 6) newStdGen)'
>     In the expression: take 10 $ (randomRs (1, 6) newStdGen)
>     In an equation for `it': it = take 10 $ (randomRs (1, 6) newStdGen)
>
>
> I have tried a variety of options, like wrapping it in a "do" or adding
> type annotations.
> Nothing seems to work.
>
>
>
> -----Original Message-----
> From: Beginners [mailto:[email protected]] On Behalf Of martin
> Sent: Friday, September 12, 2014 10:05 AM
> To: The Haskell-Beginners Mailing List - Discussion of primarily
> beginner-level topics related to Haskell
> Subject: Re: [Haskell-beginners] How to add a "method" to a record
>
> 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
> >
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140915/2ee704f1/attachment-0001.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 75, Issue 10
*****************************************

Reply via email to