[elm-discuss] Re: Randoms as LazyLists

2017-11-13 Thread GordonBGood
The LazyList library as it exists is seriously flawed as it crashes for many 
cases for infinite length lazy lists, which is probably why there is that 
caution. Please see my extensive PR which fixes almost every function so they 
can handle infinite length lazy lists within the guidelines.

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Re: Randoms as LazyLists

2017-11-13 Thread art yerkes
'iterate' is the right way to do what you're looking for.  No idea why they
chose to expose that.

generate : Generator a -> Seed -> LazyList a
generate generator seed =
let start = Random.step generator seed in
LL.iterate
(\(v,s) -> Random.step generator s)
start
|> LL.map Tuple.first


On Mon, Nov 13, 2017 at 1:48 AM, 'Rupert Smith' via Elm Discuss <
elm-discuss@googlegroups.com> wrote:

> On Saturday, November 11, 2017 at 6:33:34 PM UTC, art yerkes wrote:
>>
>> I always interpreted the warning in the documentation as "Don't use the
>> name LazyListView or the Nil and Cons constructors, instead using head,
>> tail and headAndTail for most pattern matchng".  I think it makes sense not
>> to use the internal representation given that Dict and Array change when
>> better implementations arise.  Does any code elm code actually pattern
>> match these instead of using the functions?  Always thought it was weird to
>> have this type exposed at all.
>>
>
> I cannot use the 'cons' constructor though, as it is not lazy enough:
>
> generate : Generator a -> Seed -> LazyList a
> generate generator seed =
> let
> ( value, newSeed ) =
> Random.step generator seed
> in
> cons value (generate generator newSeed)
>
>
> Runs out of stack space, as the recursive step is evaluated eagerly.
>
> I think it is strange to expose a type but recommend not using it. Either
> a type is opaque and cannot be used directly, or exposed and it is
> perfectly ok to use it.
>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Elm Discuss" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/elm-discuss/BM_ZmUk-vck/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> elm-discuss+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Randoms as LazyLists

2017-11-13 Thread 'Rupert Smith' via Elm Discuss
On Saturday, November 11, 2017 at 6:33:34 PM UTC, art yerkes wrote:
>
> I always interpreted the warning in the documentation as "Don't use the 
> name LazyListView or the Nil and Cons constructors, instead using head, 
> tail and headAndTail for most pattern matchng".  I think it makes sense not 
> to use the internal representation given that Dict and Array change when 
> better implementations arise.  Does any code elm code actually pattern 
> match these instead of using the functions?  Always thought it was weird to 
> have this type exposed at all.
>

I cannot use the 'cons' constructor though, as it is not lazy enough:

generate : Generator a -> Seed -> LazyList a
generate generator seed =
let
( value, newSeed ) =
Random.step generator seed
in
cons value (generate generator newSeed)


Runs out of stack space, as the recursive step is evaluated eagerly.

I think it is strange to expose a type but recommend not using it. Either a 
type is opaque and cannot be used directly, or exposed and it is perfectly 
ok to use it.


-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.