Questions tagged [f#]

F# is a succinct, expressive and efficient functional and object-oriented language for .NET which helps you write simple code to solve complex problems.

Filter by
Sorted by
Tagged with
2
votes
1answer
136 views

FP Free Monad vs OOP Dependency Injection

I've written my first moderately large project in functional style (in F#) and can see the advantages. The main challenge was to achieve the "Onion" architecture i.e. large and "smart" pure core / ...
0
votes
0answers
22 views

Alternative to bind for command validation

I am new to functional programming and I can't find the way to improve this pattern. I want my commands body as simple as this: firstValidation <| command >>= secondValidation >>= ...
0
votes
2answers
100 views

F# DDD Bank Modelisation: Aggregate Design for Event Sourcing

I am designing a toy project dealing with the bank account management in F# with Event Sourcing. I would like to get a bit of review (not really a code review) about my Commands and Events to see if ...
0
votes
1answer
43 views

F# function like reduce that return different type

I am new to functional programming and I can't find a function like reduce to build an AgreggateRoot given an EventStream: List.reduce ((aggregate, event) -> aggregate) eventList As I understand ...
1
vote
1answer
58 views

Functional Approaches to Serializing Objects to Variable-length Byte Array Output

I have a large number of record types derived from a binary format specification. So far, I've already written a computation expression builder that let’s me read structures from the files easily: ...
4
votes
1answer
76 views

List asymetry in F#

I am trying out F# for the first time with little prior theoretical functional programming knowledge. I have written a small function so calculate simple moving average on a list. Here it is: let ...
3
votes
1answer
164 views

REPL-based Workflow and Unit Testing

As a developer who has primarily been doing functional programming in F# for the last several years, I'm very attached to my REPL and use it run my code as I go, testing and refining each function as ...
3
votes
0answers
164 views

Using C# to implement an F# type provider

I am in a situation where I believe type providers would be useful. Consuming type provider in F# could be the way I finally dip my toes in F#. However, I understand that writing type providers is ...
-1
votes
1answer
1k views

Generic method with different arguments

In the following scenario: A factory returns an object of a logic class: ILogicClass object = factory.GetByRequirements(reqs); I then want to invoke a method and get some results which are in the ...
4
votes
2answers
1k views

Why not use an ORM with DDD?

I've just finished reading Scott Wlaschin's excellent book "Domain Modeling Made Functional: Tackle Software Complexity with Domain-Driven Design and F#" in which he uses the F# SQL type provider for ...
1
vote
0answers
61 views

Dependency on local function

So I have a design question, I was reading about Dependency Injection on fsharpforfunandforprofit.com and the article said that hidden dependencies on local methods is a problem. That got me thinking, ...
4
votes
1answer
493 views

Should function composition and piping be tested?

Unit testing requires writing tests first then code, on the other hand in F# (and most of the functional languages) some codes are extremely short as follows: let f = getNames >> Observable....
2
votes
1answer
97 views

What is the term for different types that contain the same information?

What is the correct term(s) for different types that contain exactly the same information? For example (F#): type Type1 = (int * string) type Type2 = (string * int) When describing that these types ...
3
votes
2answers
219 views

How/if to test basic combinations of already tested functions

Sorry for the long-winded question. I hope the question and its potential answers can serve as a useful example to developers who are wondering where to set the bar regarding testing fairly simple ...
3
votes
1answer
517 views

functional programming with mutating request object

Following uses JavaScript code but F# is tagged for input from functional programmers. I understand that in functional programming we shouldn't mutate the state or incoming parameters but I'm ...
1
vote
0answers
75 views

F# convention for brace placement

Is there a generally accepted convention for brace placement in F#? I found some examples in the documentation, but they didn't seem to be consistent with each other. In particular, and to take an ...
2
votes
0answers
169 views

combine reader monad with choice

I have this two types open FSharpx open FSharpx.Reader type First = { Name: string Items: string list } type Second = { Name: string Numbers: int list } Using a Reader monad ...
2
votes
1answer
86 views

F# - Associating a function with the matching type of object

Let's say I'm programming a chess game. At some point I have to check, which moves are valid for a given piece. What would be the proper way to select the correct pathfinding function for a given ...
1
vote
0answers
228 views

What are the types of tasks for which Functional Programming paradigm really wins over imperative one? [closed]

During its evolution C# gradually gets more and more features which belong to functional paradigm. Subjectively these features allow (at least me) to be more productive, fluent and write maintainable ...
0
votes
2answers
186 views

Is the “_” character in the first anonymous function a wildcard?

Given this function let readInput() = Seq.initInfinite (fun _ -> Console.ReadLine()) |> Seq.takeWhile (fun s -> s <> null) ` |> Seq.map int` is the _ in the function called by ...
1
vote
1answer
194 views

wooden floor seam staggering algorithm

I will soon install wooden parquet floor in my home. And just for fun, I am thinking of writing an algorithm for making efficient use of the wooden planks I have. Here's the problem: I have planks ...
3
votes
1answer
201 views

Why the name MailboxProcessor in F#?

It seems that the standard practice is to immediately alias MailboxProcessor<'T> to Agent<'T>. So why the name in the first place anyways? Why don't they just call it Agent<'T>, if ...
7
votes
1answer
285 views

Why does FSharpLint suggest, “In F# code, use 'e1 || e2' instead of 'e1 or e2'”

If I write the expression, if not (expr1 or expr2) then value I get the following warning from FSharpLint, In F# code, use 'e1 || e2' instead of 'e1 or e2'. Why is using || preferred over using or? ...
5
votes
2answers
230 views

What is the difference between explicit parameters and closures

In F#, a tail recursive List.filter function can be implemented like: let filter f = let rec filterImpl f acc = function | [] -> List.rev acc | h :: t -> filterImpl f (if f ...
3
votes
3answers
319 views

Declarative programming for deterministic real time control

Let's say you want control a motor in real time. Normally you would use a microcontroller or PC with e.g. c-programming language. So you would use an imperative approach. You tell the microcontroller ...
3
votes
1answer
72 views

Handling continuations within a priority queue

I am attempting to determine the best way to handle actions that must occur in passes. Many of these actions use objects that were created in a previous pass. The solution I have come up with is to ...
2
votes
1answer
685 views

How to improve performance for serializing and deserializing a large object graph?

I have a large object graph in .NET (F# as it happens) that I need to persist to disk and then will load again periodically for use in a calculation. The performance of deserializing is more ...
3
votes
3answers
143 views

Split a File into Multiple Objects Functionally

I want to read a file into a collection of objects. The data (it's a Leica PTX file if you're curious) is formatted as follows: 640 [begin item #1: number of columns] 480 [number of rows] 0 0 0 [...
3
votes
3answers
597 views

Which scenarios to use .NET Concurrent Collections effectively?

I am investigating how to introduce parallelism into an application to improve performance. In particular, I am looking at parallel for loops and their variants and my initial experiments show ...
1
vote
1answer
172 views

What is the point of an Expr in vanilla F#? How can it be applied? [closed]

Without using the power pack to convert Expr to C# expressions, it seems like once I create an Expr, the only thing I can do with it is either print out a string representation of it, or...create ...
1
vote
2answers
106 views

arbitrary data shared between plugins

I'm making a program that supports plugins. The program is being written in F#. The program maintains a single object that represents the state of the program. When a plugin is invoked, it takes ...
4
votes
1answer
522 views

F# MailboxProcessor aka Agent as an API

Seeing how there's raise in actor-based solutions, I'm a bit confused about the lack of F# libs that use something like the stock MailboxProcessor as the API. What's the downside? Why deal with ...
5
votes
2answers
419 views

How to define IntsWithoutZero type in f#

Recently I saw a great video of Scott Wlaschin about patterns in functional programming. He gives an example of dividing a numbers. In f# we'd use int option for the result to handle division by zero ...
1
vote
1answer
244 views

Does F# require .NET runtime and libraries to run?

Does F# like C# requires .NET framework to run? According to Wikipedia as stated below, F# is mostly used as a CLI language which means that it is used mostly with .NET. But it also states that the F# ...
2
votes
2answers
317 views

Functional Programming style: How to write functions - explicit currying, implicit currying or lamdas?

So I have been using F# for a while and studying a bit of Haskell on the side and I have realized I could rewrite the exact same function one of three different ways. Either with implicit currying, ...
1
vote
2answers
1k views

What is idiomatic way in f# to express sequence of if statements with overlapping conditions

Let's say I got code like this: if(conditionA) do something if(conditionA && conditionB) do something more Obviously, I could nest the ifs (although when there are more complicated ...
18
votes
1answer
2k views

Confusion between F# and C# [duplicate]

I am fairly new to functional programming and C#/F#. What is unclear to me is: Can you do functional programming in C# and/or in F#? Or is it something like, you write some OO code in C#, and some FP ...
5
votes
2answers
2k views

In what way are union types better for correctness than a common interface?

I've just recently started familiarising myself with functional programming, mostly via F#, and there's one particular functional idiom that I'm not fully understanding the benefits of. I've seen it ...
5
votes
1answer
945 views

What and how much domain code should be put in an F# module

According to recommendations given here, F# modules should correspond to DDD bounded contexts, i.e. subdivisions of a business domain. The bounded context I'm working on right now has 2 aggregates ...
5
votes
1answer
908 views

Best way to handle language interoperability

Background In a language like F#, direct interoperability with most other .NET languages is possible. For example, it is possible to use classes written in C# directly in F#, and it is possible to ...
3
votes
3answers
1k views

simple let binding vs constant function

I understand the reasons why I would prefer let a = f(x) over let a() = f(x), especially when f takes is a long running function. I also think it is correct to say, that, considering lambda calculus ...
3
votes
1answer
341 views

What is the value of a let expression

From what I understand, every code in f# is an expression, including let binding. Say we got the following code: let a = 5 printfn "%d" a I've read that this would be seen by the compiler as let a =...
0
votes
0answers
149 views

Can a type provider mimic an anonymous class?

I'm working on building a website using the F# MVC 5 template, and I noticed that the template creator uses formally declared types for the route defaults. In VB.Net and C#, this is typically done ...
5
votes
1answer
196 views

Why are F# exceptions generally not suffixed with 'Exception'?

In .NET, it is idiomatic to suffix exception types with Exception. But most, if not all, sources I have seen for custom exception types in F# don't follow this idiom. Most seem to use the suffix ...
11
votes
2answers
929 views

Why does F# Core define generic array types?

I just noticed that the FSharp.Core namespace includes generic array types of up to 4 dimensions, i.e. Core.[]<'T>, Core.[,]<'T>, etc. C# and VB seem to be doing just fine with System.Array - ...
16
votes
4answers
4k views

Is pattern-matching against types idiomatic or poor design?

It seems like F# code often pattern matches against types. Certainly match opt with | Some val -> Something(val) | None -> Different() seems common. But from an OOP perspective, that looks ...
28
votes
3answers
5k views

Why not annotate function parameters?

To make this question answerable, let's assume that the cost of ambiguity in the mind of a programmer is much more expensive then a few extra keystrokes. Given that, why would I allow my teammates to ...
11
votes
1answer
3k views

How do I approach a serious F# project without C# knowledge?

So, essentially the project I wish to undertake is an SVG editor. I would prefer to use WPF because then I can leverage XAML for my application layout (that designer is so nifty). Unfortunately, I ...
4
votes
3answers
940 views

Is there a way to created nested computation expressions?

In F#, I want to build a hierarchical data structure in a way with a minimum amount of language noise. The actual problem is trying to build an RSpec inspired framework using F#. RSpec allows the ...
5
votes
3answers
4k views

Why C# is not statically typed but F# and Haskell are?

There was a talk given by Brian Hurt about advantages and disadvantages of static typing. Brian said that by static typing he don't mean C#, but F# and Haskell. Is it because of dynamic keyword added ...