Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  What to use when you need random values? (mike h)
   2.  Improve my lambda expressions (PATRICK BROWNE)
   3. Re:  Improve my lambda expressions (Silent Leaf)


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

Message: 1
Date: Mon, 26 Jun 2017 09:18:06 +0000 (UTC)
From: mike h <mike_k_hough...@yahoo.co.uk>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] What to use when you need random
        values?
Message-ID: <1681965374.3354616.1498468686...@mail.yahoo.com>
Content-Type: text/plain; charset="utf-8"

This post is a useful discussion on randomness . Abstract Nonsense

  
|  
|   |  
Abstract Nonsense
   |  |

  |

 
 

    On Friday, 23 June 2017, 16:11, David McBride <toa...@gmail.com> wrote:
 

 When you are unsure about the differences between functions, it can be
good to read the haddocks for the library.

http://hackage.haskell.org/package/random-1.1/docs/System-Random.html

The standard haskell random library supports the idea of splitting a
seed randomly.  You take one seed and split it, and now you  have two
seeds, which will each generate different randoms independently.
getStdGen gets the current global seed.  newStdGen splits new a seed
off of the current global seed.  mkStdGen allows you to create a seed
from a value so that you can get the same set of randoms repeatedly.

I would say if you are in IO, just use randomRIO.  If you are in
monadic code that not IO at its base, you should use MonadRandom
library on hackage.  Quickcheck randomness is only really used in
quickcheck, although it is probably based off the standard libraries.

Just keep in mind that randomness is a concept that is a little hard
to wrap your head around in haskell until you've been using it a
little while.

On Fri, Jun 23, 2017 at 10:24 AM, Silent Leaf <silent.le...@gmail.com> wrote:
> Hi,
> I've had trouble finding the best way(s) to use random values in haskell, as
> it seems like there are several modules that either do the same thing or
> reuse one another i'm not sure.
>
> There is System.Random
> - is it better to use the streams random(R)s or a more imperative randomRIO?
> - is it better to use mkStdGen or newStdGen or getStdGen?
> There is Test.QuickCheck and its type(class?) Gen
> There is a module in Control.Monad (i think) which exports the type Rnd
>
> What about performances, and all those options? What do you like to use with
> random numbers?
>
> I know that's a lot of questions. feel free to only answer to a few of them.
> :)
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20170626/3ecb746a/attachment-0001.html>

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

Message: 2
Date: Mon, 26 Jun 2017 10:38:10 +0100
From: PATRICK BROWNE <patrick.bro...@dit.ie>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: [Haskell-beginners] Improve my lambda expressions
Message-ID:
        <CAGFLrKeuKAhayGOh_OEnOzOHV=z-hqzbnxm_yqd9xcvgy3n...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

The code below provides a distance function that works for points and
moving point.
I am happy with the result, but I have a problem with the lambda
expressions.
Instead of supplying an argument to each 'mpXX', is it possible to have a
single lambda argument on the entire final 'md' function? (e.g. 'md 2')
Thanks in advance,
Pat

data Point a = Point { abscissa :: a, ordinate :: a } deriving Show
dist a b = sqrt (((abscissa a) - (abscissa b))^2 + ((ordinate a) -
(ordinate b))^2)

-- Sttic points
p1, p2 :: Point Float
p1 = Point 0.0 0.0
p2 = Point 4.0 4.0
d = dist p1 p2


-- Moving points
mp1, mp2 :: Point Float
mp1x = (\t -> 4.0 + 0.5 * t)
mp1y = (\t -> 4.0 - 0.5 * t)
mp1 = Point (mp1x 2) (mp1y  2)
mp2x  = (\t -> 0.0 + 1.0 * t)
mp2y  = (\t -> 0.0 - 1.0 * t)
mp2 = Point (mp2x 2) (mp2y 2)
md = dist mp1 mp2

-- 


This email originated from DIT. If you received this email in error, please 
delete it from your system. Please note that if you are not the named 
addressee, disclosing, copying, distributing or taking any action based on 
the contents of this email or attachments is prohibited. www.dit.ie

Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí 
earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an 
seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon 
dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa 
ríomhphost nó sna hiatáin seo. www.dit.ie

Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to 
Grangegorman <http://www.dit.ie/grangegorman>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20170626/c7fef45e/attachment-0001.html>

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

Message: 3
Date: Mon, 26 Jun 2017 12:37:01 +0200
From: Silent Leaf <silent.le...@gmail.com>
To: patrick.bro...@dit.ie,  The Haskell-Beginners Mailing List -
        Discussion of primarily beginner-level topics related to Haskell
        <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Improve my lambda expressions
Message-ID:
        <CAGFccjOScUFT5=cywyn4t64rxtu0_ywksvwubdl-towxarl...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

yes you can, it's actually better to encapsulate all "lambdas" and
intermediate values inside one function, provided you never use them
anywhere else.
i advise using "where" as such:

md n = dist (Point (fx n) (fy n)) (Point (gx n) (gy n))
  where fx n = 4.0 + 0.5 * n
        fy n = 4.0 - 0.5 * n
        gx n = n * 1.0
        gy n = n * (-1.0)
-- then you can call "foo = md 2"

it's more idiomatic to use where, i believe. however you can also choose to
define the helpers before the expression defining the function, using "let
... in" like that:

md n = let fx n = 4.0 + 0.5 * n
           fy n = 4.0 - 0.5 * n
           gx n = n * 1.0
           gy n = n * (-1.0)
       in dist (Point (fx n) (fy n)) (Point (gx n) (gy n))

be careful about the alignment. both ways are (in this example) strictly
equivalent, it all depends on circumstances and taste.

mind you if you don't want a function to be reused, merely one single value
foo = md 2, you can always just write directly:
foo = dist (Point (fx 2) (fy 2)) (Point (gx 2) (gy 2))
  where fx n = 4.0 + 0.5 * n
        fy n = 4.0 - 0.5 * n
        gx n = n * 1.0
        gy n = n * (-1.0)

2017-06-26 11:38 GMT+02:00 PATRICK BROWNE <patrick.bro...@dit.ie>:

> The code below provides a distance function that works for points and
> moving point.
> I am happy with the result, but I have a problem with the lambda
> expressions.
> Instead of supplying an argument to each 'mpXX', is it possible to have a
> single lambda argument on the entire final 'md' function? (e.g. 'md 2')
> Thanks in advance,
> Pat
>
> data Point a = Point { abscissa :: a, ordinate :: a } deriving Show
> dist a b = sqrt (((abscissa a) - (abscissa b))^2 + ((ordinate a) -
> (ordinate b))^2)
>
> -- Sttic points
> p1, p2 :: Point Float
> p1 = Point 0.0 0.0
> p2 = Point 4.0 4.0
> d = dist p1 p2
>
>
> -- Moving points
> mp1, mp2 :: Point Float
> mp1x = (\t -> 4.0 + 0.5 * t)
> mp1y = (\t -> 4.0 - 0.5 * t)
> mp1 = Point (mp1x 2) (mp1y  2)
> mp2x  = (\t -> 0.0 + 1.0 * t)
> mp2y  = (\t -> 0.0 - 1.0 * t)
> mp2 = Point (mp2x 2) (mp2y 2)
> md = dist mp1 mp2
>
> This email originated from DIT. If you received this email in error,
> please delete it from your system. Please note that if you are not the
> named addressee, disclosing, copying, distributing or taking any action
> based on the contents of this email or attachments is prohibited.
> www.dit.ie
>
> Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí
> earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an
> seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon
> dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa
> ríomhphost nó sna hiatáin seo. www.dit.ie
>
> Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to
> Grangegorman <http://www.dit.ie/grangegorman>
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20170626/72891fac/attachment.html>

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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 108, Issue 16
******************************************

Reply via email to