Defining new optics with `<&>` does not seem to work like in the documentation
See original GitHub issueDescription
I wanted to define optics over a custom data type. Failed to do it with the approach given by the documentation, and then succeeded by doing it differently. I don’t fully understand the consequences of this, but I get the sense something is wrong – either with what I do, or the documentation.
Repro steps
> open FSharpPlus.Lens ;;
> type Person<'TName> = { Name : 'TName; Age : int } ;;
type Person<'TName> =
{Name: 'TName;
Age: int;}
> (* Let's do it like in the documentation; that looks neat! *) ;;
> let inline _name f { Name = n; Age = a } = f n <&> fun n' -> { Name = n'; Age = a } ;;
val inline _name :
f:('a -> ^b) -> Person<'a> -> ^_arg4
when ( ^b or ('c -> Person<'c>)) : (static member ( <&> ) : ^b *
('c ->
Person<'c>)
-> ^_arg4)
> (* Okay, so that looks like it might have succeeded. *) ;;
> (* Let's find a person try to it on. *) ;;
> let me = { Name = "Chris"; Age = 39 } ;;
val me : Person<string> = {Name = "Chris";
Age = 39;}
> (* Oops, I meant to be slightly more anonymous. *) ;;
> setl _name "kqr" me ;;
setl _name "kqr" me ;;
-----^^^^^
/home/kqr/stdin(33,6): error FS0001: Expecting a type supporting the operator '<&>' but given a function type. You may be missing an argument to a function.
On the other hand, if I re-create the optic with the lens
helper function, things seem to work better:
> let inline _name f = lens (fun p -> p.Name) (fun p n -> { Name = n; Age = p.Age }) f ;;
val inline _name :
f:('a -> ^b) -> (Person<'a> -> ^c)
when (FSharpPlus.Control.Map or ^b or ^c) : (static member Map : ( ^b *
('d ->
Person<'d>)) *
FSharpPlus.Control.Map
->
^c)
> setl _name "kqr" me ;;
val it : Person<string> = {Name = "kqr";
Age = 39;}
Related information
- Debian Stretch
- Version 1.0.0 of FSharpPlus
- Microsoft ® F# Interactive version 4.1 – .NET Core SDK 3.0.100-preview8-013656
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (10 by maintainers)
Top Results From Across the Web
Fix the OCR error Could Not Perform Recognition in Acrobat
Solution 1: Obtain a version of the document that does not contain renderable (editable) text. This message appears if the PDF document already ......
Read more >Use fonts in InDesign
InDesign supports Variable fonts, which is a new OpenType font format that supports custom attributes, such as weight, width, slant, optical ...
Read more >Optical Character Recognition (OCR) - AppSheet Help
AppSheet's OCR feature can be used when you need to scan multiple documents that all have a fixed layout. The image may contain...
Read more >sklearn.cluster.OPTICS — scikit-learn 1.3.0 documentation
OPTICS (Ordering Points To Identify the Clustering Structure), closely related to DBSCAN, finds core sample of high density and expands clusters from them...
Read more >Define a user-trained SDU model
The Smart Document Understanding tool uses optical character recognition (OCR) to extract text from images in the files that it analyzes. Images must...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ideally both. A quick update: unfortunately we’re still trying to get back the doc generation and trying to understand why from one day to another it started failing. @wallymathieu is doing some efforts in order to get it working again.
I added a note in the docs, sorry again for the confusion. Hopefully no more devs fall in the trap.