New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random functor monad #51

Merged
merged 3 commits into from Jun 30, 2015

Conversation

Projects
None yet
3 participants
@imeckler
Contributor

imeckler commented Dec 14, 2014

I added functions

map : (a -> b) -> Generator a -> Generator b

and

andThen : Generator a -> (a -> Generator b) -> Generator b

to the Random module. Is there another name you prefer to andThen? I was shooting for consistency with the Maybe module. Also, does anyone have any ideas about a uniform convention for Applicative "instances"? Currently Random exports pair : Generator a -> Generator b -> Generator (a, b), but as far as I can tell no other module exports a function of the same name.

@kasbah

This comment has been minimized.

Show comment
Hide comment
@kasbah

kasbah Feb 21, 2015

Contributor

+1 to merge this, I was looking for these and had started to write them myself.

Contributor

kasbah commented Feb 21, 2015

+1 to merge this, I was looking for these and had started to write them myself.

@kasbah

This comment has been minimized.

Show comment
Hide comment
@kasbah

kasbah Feb 21, 2015

Contributor

Though I found your shadowing of generate a bit confusing. I had written this map:

map : (a -> b) -> Generator a -> Generator b
map f (Generator g) = Generator <| (\(v,seed) -> (f v, seed)) << g

and I changed your andThen to

andThen : Generator a -> (a -> Generator b) -> Generator b
andThen (Generator g) f = Generator <| \seed ->
    let (v,seed')     = g seed
        (Generator h) = f v
    in h seed'

for my own use.

Contributor

kasbah commented Feb 21, 2015

Though I found your shadowing of generate a bit confusing. I had written this map:

map : (a -> b) -> Generator a -> Generator b
map f (Generator g) = Generator <| (\(v,seed) -> (f v, seed)) << g

and I changed your andThen to

andThen : Generator a -> (a -> Generator b) -> Generator b
andThen (Generator g) f = Generator <| \seed ->
    let (v,seed')     = g seed
        (Generator h) = f v
    in h seed'

for my own use.

@evancz evancz merged commit 9027458 into elm:master Jun 30, 2015

1 check failed

continuous-integration/travis-ci The Travis CI build could not complete due to an error
Details
@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Jun 30, 2015

Member

Thanks @imeckler, I think this will come in handy!

Member

evancz commented Jun 30, 2015

Thanks @imeckler, I think this will come in handy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment