FSharpPlus icon indicating copy to clipboard operation
FSharpPlus copied to clipboard

Conseable types

Open robkuz opened this issue 8 years ago • 11 comments

Is there a standard static member for types that are Conseable? In principle anything that can be mapped to a List or Seq could be conseable. No?

robkuz avatar Jan 11 '17 17:01 robkuz

Yes, looks like it can be added to the Collection abstraction which represents everything that is List-like but doesn't fit well in the Monoid or Foldable which are the preferred abstractions.

However I think its use will be more theoretical than practical since cons is an operation that is a bit tied to the structure, I mean for linked lists is natural and cheap but for sequences is not.

Do you have an interesting problem to be solved with a generic cons ?

gusty avatar Jan 12 '17 07:01 gusty

This might be relevant: http://stackoverflow.com/questions/11437269/haskell-append-type-class

gusty avatar Feb 21 '17 14:02 gusty

I felt like cons operator would be nice when dealing with List, DList and NonEmptyList

wallymathieu avatar Mar 28 '20 20:03 wallymathieu

Vectors (#192) will also benefit from this.

cannorin avatar Mar 29 '20 07:03 cannorin

What would be such generic operator or method name?

gusty avatar Mar 29 '20 08:03 gusty

Maybe Unfoldable? (vectors are not going to follow the laws, though...)

cannorin avatar Mar 29 '20 08:03 cannorin

So you mean to add the generic insert function?

gusty avatar Mar 29 '20 10:03 gusty

Would insert make sense from a f# / .net perspective ?

wallymathieu avatar Mar 29 '20 13:03 wallymathieu

To me insert sounds more like insert something somewhere in the middle. It's not clearer than cons and snoc which tells exactly where the insertion is going to happen.

gusty avatar Mar 29 '20 13:03 gusty

Perhaps that the abstraction should be called Unfoldable and then we could add cons or add.

wallymathieu avatar Mar 29 '20 13:03 wallymathieu

Note that the name of the abstraction is only relevant for our docs as they are not reflected in the code, more than maybe a filename.

gusty avatar Mar 29 '20 13:03 gusty