An error like F # with one level of indentation and not with another

I am looking through the Hopac documentation and I came across this weird error like:

let create x = Job.delay <| fun () ->
    let c = {reqCh = Ch (); replyCh = Ch ()}
    Job.iterateServer x <| fun x ->
        c.reqCh >>= function
          | Get -> c.replyCh *<- x >>-. x
          | Put x -> Job.result x
    >>-. c

Scrapers.SC.fsx(48,10): error FS0001: Type mismatch. Expecting a
    ''a'    
but given a
    'Cell<'a>'    
The types ''a' and 'Cell<'a>' cannot be unified.

cis Cell<'a>. This code compiles fine with the code from the page:

let create x = Job.delay <| fun () ->
  let c = {reqCh = Ch (); replyCh = Ch ()}
  Job.iterateServer x <| fun x ->
        c.reqCh >>= function
          | Get -> c.replyCh *<- x >>-. x
          | Put x -> Job.result x
  >>-. c

The only difference between the two is the depth of the first indent - 2, not 4.

Usually, when there is a problem with indentation, I get a warning “Perhaps indentation is incorrect”, and not a type error. Therefore, it must be really confusing.

I've been using F # for ten years now, and I still don't understand the indentation rules.

What am I missing?

+4
source share
2 answers

>>-. - 4 , , . ,

    expr
 |> f1
 |> f2

.

+4

, "2 4 ", c.reqCh. c.reqCh iterateServer, - . ( https://github.com/fsharp/fslang-suggestions/issues/470 ), , , c.reqCh iterateServer, - F # , . ( , , ).

, c.reqCh ? , , ?

let create x = Job.delay <| fun () ->
    let c = {reqCh = Ch (); replyCh = Ch ()}
    Job.iterateServer x <| fun x ->
         c.reqCh >>= function
           | Get -> c.replyCh *<- x >>-. x
           | Put x -> Job.result x
    >>-. c

, c.reqCh iterateServer, 4- , ? , . ( , ).

, , <| iterateServer , :

let create x = Job.delay <| fun () ->
    let c = {reqCh = Ch (); replyCh = Ch ()}
    Job.iterateServer x (fun x ->
        c.reqCh >>= function
          | Get -> c.replyCh *<- x >>-. x
          | Put x -> Job.result x
    ) >>-. c

, ? , <|, .

+1

Source: https://habr.com/ru/post/1672878/


All Articles