question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Defining new optics with `<&>` does not seem to work like in the documentation

See original GitHub issue

Description

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:closed
  • Created 4 years ago
  • Comments:15 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
gustycommented, Dec 8, 2019

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.

1reaction
gustycommented, Jan 22, 2020

I added a note in the docs, sorry again for the confusion. Hopefully no more devs fall in the trap.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found