Questions tagged [computation-expression]

Computation expressions in F# is a technique for writing computations that can be combined using control flow constructs and bindings.

Computation expressions are derived from , which in turn represent programming implementation of monads, a mathematical concept in .

Computation expressions are usually implemented by a developer as a set of functions, while the F# development environment provides the means of indirect calling of these functions with a variety of keywords and other syntactic constructs (see ).

Further reading:
F# Programming/Computation Expressions on WikiBooks
Computation Expressions on MSDN
F# 2.0 Language Specification/Computation Expressions

134 questions
1
vote
1 answer

How to correctly discard result of a (monadic) computation in F#

In Haskell, I can write: token: Parser a -> Parser a token p = do space v <- p space return v In F#, I have come this far: let token = compose { let! _ = space let! v = parser let! _…
Paul Kapustin
  • 3,297
  • 5
  • 35
  • 45
1
vote
4 answers

How do I turn a forward pipe expression into a computation expression?

So, I want to build a custom computation expression that would allow me to turn this - testWorld |> subscribe ClickTestButtonAddress [] addBoxes |> addScreen testScreen TestScreenAddress |> setP (Some TestScreenAddress)…
Bryan Edds
  • 1,696
  • 12
  • 28
1
vote
1 answer

F# laziness in quoted computation expressions

Using the Quote member on a computation expression to convert the workflow into an AST, but would like it be such that the GetEnumerator() is not actually called on the sequence as the quotation is constructed (i.e., have some form of laziness). In…
1
vote
1 answer

What is the purpose of the Zero member when defining F# computation expressions?

I am trying to learn F# computation expressions. In general, what is the purpose of the Zero member? What is its definition for sequences? What is its definition for async workflows?
mushroom
  • 6,201
  • 5
  • 36
  • 63
0
votes
1 answer

How to modify this CE to return Error as a single item vs. a list, in F#?

I asked another question about how to make an application async/result expression. User @Brian_Berns came up with a very good answer: Is there an async validate lib for F#? The only caveat is that the Error part of a Result needs to be in an array,…
Thomas
  • 10,933
  • 14
  • 65
  • 136
0
votes
1 answer

can't compile code in computation expression, in F#

I have this function: let rec retryAsync<'a> (shouldRetry: 'a -> bool) (retryIntervals: TimeSpan list) (onRetryNotice: int -> unit) (request: unit -> Async<'a>) : Async<'a> = async { let! result = request() match shouldRetry…
Thomas
  • 10,933
  • 14
  • 65
  • 136
0
votes
1 answer

F# passing state into a function in Bind

This is an evolution of the question I asked here (F# Binding to output while carrying the state). I am trying to get the Bind method to take a function with this signature PlanAccumulator<'a> -> PlanAccumulator<'b>. The getFood function is an…
Matthew Crews
  • 4,105
  • 7
  • 33
  • 57
0
votes
1 answer

How can I go about building a recursive computation expression builder

What I would like to do is have a function that I can repeatedly pass a transformation function into and receive a combined transformation, the transformation function would be of the form 'a -> 'b i.e. rather than compose a fixed workflow like…
7sharp9
  • 2,147
  • 16
  • 27
0
votes
1 answer

Printf-like function in F# computation expression

I'm trying to write a code in F# that allows logging to custom source and using generating random number sing swappable implementations. Instead of passing logging function/random generator to every function in the application, I'm trying to pass…
ghord
  • 13,260
  • 6
  • 44
  • 69
0
votes
1 answer

how do i fix these errors generated by my computational expression that is using my custom workflow builder?

From the MSDN documentation I understand that if Run is implemented it will be called automatically at the end of the computational expression. It says that: builder.Run(builder.Delay(fun () -> {| cexpr |})) will be generated for the computational…
Charles Lambert
  • 5,042
  • 26
  • 47
0
votes
1 answer

gettings attributes of f in a bind

I have a bit of code in a workflow where I'd like to get the attributes to a function the expression is this let! accounts = _accounts() and in my bind I have this member this.Bind(x,f) = let attributes = f.GetType() …
Rune FS
  • 21,497
  • 7
  • 62
  • 96
0
votes
0 answers

Can I add params to computation expressions constructors in F#

Given the following code type Init<'a> = Init of 'a type Right<'a> = Right of 'a type Left<'a> = Left of 'a type MovesBuilder(init) = member x.Yield(()) = Init init [] member x.Left(Init v) = Left "Left" …
robkuz
  • 9,488
  • 5
  • 29
  • 50
0
votes
0 answers

Concurrent Download with limited number of Workers and AsyncSeq from FSharpX (or ExtCore)

I try a concurrent download with limited number of Workers using the AsyncSeq module. Based on the FSharpX example of https://github.com/fsprojects/fsharpx/blob/master/samples/Crawler.fsx let rec concurrentDownload concurrentWorkers download…
0
votes
2 answers

F# Computation Expression - Type woes

I'm fighting with a few pathetic lines of code but cannot wrap my head around the problem - for whatever reason I can't get under the principle of this aspect of F#'s type system and so far all my reading hasn't worked. Can anyone point out to me…
Richard Griffiths
  • 758
  • 1
  • 11
  • 23
1 2 3
8
9