Skip to content
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

Add LazyList.consLazy #134

Open
brianberns opened this issue Jun 5, 2019 · 1 comment
Open

Add LazyList.consLazy #134

brianberns opened this issue Jun 5, 2019 · 1 comment

Comments

@brianberns
Copy link

brianberns commented Jun 5, 2019

Description

Conceptually, a LazyList<'T> contains a head of type 'T and a tail of type Lazy<LazyList<'T>>. Strangely, there is no direct way to construct such a lazy list using the current API. The best can be done is LazyList.consDelayed head (fun () -> tail.Value), which is unnecessarily wasteful.

I suggest a new function for creating such a list: LazyList.consLazy (head : <'T>) (tail : Lazy<LazyList<'T>>).

For bonus points, also provide an infix operator that can be used for clarity. I suggest something like (@).

Desired result

I should be able to create an infinite list of 1's like this: let rec ones = 1 @ lazy ones.

Known workarounds

consDelayed can be used but it is inelegant and wasteful.

@gdziadkiewicz
Copy link
Collaborator

In F# @ is the list concatenation operator. To make it more aligned with the language shouldn't it be something along the lines of cons ::?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants