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

[WIP] Basic collections #1

Open
WhiteBlackGoose opened this issue Jun 22, 2022 · 0 comments
Open

[WIP] Basic collections #1

WhiteBlackGoose opened this issue Jun 22, 2022 · 0 comments

Comments

@WhiteBlackGoose
Copy link
Member

WhiteBlackGoose commented Jun 22, 2022

Option

Do we need options? Here some ideas for nullables. Having option type might be not a good idea, beacuse it's definitely incompatible with both C#'s nullables and F#'s options.

But we probably cannot depend on FSharp.Core, so we either do nullables (which aren't so good when working with old BCL or 3rd party API) or we do our own option. Or...?

Regardless of what we choose, I'm going to use Option<T> as if we already decided what it is.

Sequences

Type Seq<T>

We can write our own API and back it with Linq whenever possible.

map : (T -> U) -> Seq<T> -> Seq<U>
where : (T -> Bool) -> Seq<T> -> Seq<T>
flatten : (T -> Seq<U>) -> Seq<T> -> Seq<U>
fold : (T * A -> A) -> A -> Seq<T> -> A
append : T -> Seq<T> -> Seq<T>
prepend : T -> Seq<T> -> Seq<T>
product : Seq<T1> * Seq<T2> -> Seq<T1 * T2>
product : Seq<T1> * Seq<T2> * Seq<T3> -> Seq<T1 * T2 * T3>
// potentially auto-generated overloads for product for any number of type arg
zip : Seq<T1> * Seq<T2> -> Seq<T1 * T2>
zip : Seq<T1> * Seq<T2> * Seq<T3> -> Seq<T1 * T2 * T3>
// potentially auto-generated overloads for zip for any number of type arg

Singly linked list

type FreshList<T> =
    | Nil
    | Cons(Element, FreshList<T>)

However since it's not functional-first language, I don't think we want to replace List<T> with this one. Should we choose another name?

Map

type FreshMap<TKey, TValue> = 
    ...
    member Add : TKey * TValue -> FreshMap<TKey, TValue>
    member Remove : TKey * TValue -> FreshMap<TKey, TValue>
    member Item : TKey -> TValue
    member TryGet : TKey -> Option<TValue>

Set

type FreshSet<T> = 
    ...
    member Add : T -> FreshSet<T>
    member Remove : T -> FreshSet<T>
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

1 participant