17,020
questions
418
votes
15
answers
80k
views
Is functional GUI programming possible? [closed]
I've recently caught the FP bug (trying to learn Haskell), and I've been really impressed with what I've seen so far (first-class functions, lazy evaluation, and all the other goodies). I'm no expert ...
218
votes
8
answers
26k
views
In what areas might the use of F# be more appropriate than C#? [closed]
Over the last few years F# has evolved into one of Microsoft's fully supported languages employing many ideas incubated in OCaml, ML and Haskell.
Over the last several years C# has extended its ...
146
votes
3
answers
22k
views
Getting started with F# [closed]
How do I go about getting into F# programming?
What are some good starter samples to learn the language, or learn about some of its advantages over other languages?
What tools do I need (e.g. ...
143
votes
5
answers
49k
views
Difference between fold and reduce?
Trying to learn F# but got confused when trying to distinguish between fold and reduce. Fold seems to do the same thing but takes an extra parameter. Is there a legitimate reason for these two ...
135
votes
9
answers
71k
views
How to create a sequence of integers in C#?
F# has sequences that allows to create sequences:
seq { 0 .. 10 }
Create sequence of numbers from 0 to 10.
Is there something similar in C#?
135
votes
5
answers
33k
views
What are the primary differences between Haskell and F#? [closed]
I've searched on the Internet for comparisons between F# and Haskell but haven't found anything really definitive. What are the primary differences and why would I want to choose one over the other?
131
votes
3
answers
29k
views
F# changes to OCaml [closed]
F# is derived from OCaml, but what major items are missing or added? Specifically I'm curious as to whether the resources available for learning OCaml are also useful to someone who wants to learn F#.
128
votes
1
answer
23k
views
Why is this F# code so slow?
A Levenshtein implementation in C# and F#. The C# version is 10 times faster for two strings of about 1500 chars. C#: 69 ms, F# 867 ms. Why? As far as I can tell, they do the exact same thing? Doesn't ...
120
votes
4
answers
11k
views
Best approach for designing F# libraries for use from both F# and C#
I am trying to design a library in F#. The library should be friendly for use from both F# and C#.
And this is where I'm stuck a little bit. I can make it F# friendly, or I can make it C# friendly, ...
117
votes
3
answers
23k
views
Object initialization syntax
I'm just starting out with F# and I can't find the syntax to do object initialization like in C# 3.
I.e. given this:
public class Person {
public DateTime BirthDate { get; set; }
public string ...
116
votes
6
answers
11k
views
Why are functions in OCaml/F# not recursive by default?
Why is it that functions in F# and OCaml (and possibly other languages) are not by default recursive?
In other words, why did the language designers decide it was a good idea to explicitly make you ...
110
votes
10
answers
30k
views
Haskell composition (.) vs F#'s pipe forward operator (|>)
In F#, use of the the pipe-forward operator, |>, is pretty common. However, in Haskell I've only ever seen function composition, (.), being used. I understand that they are related, but is there ...
108
votes
7
answers
19k
views
F# development and unit testing? [closed]
I just got started with F#, which is my first functional language. I have been working quasi-exclusively with C#, and enjoy a lot how F# leads me to re-think how I write code. One aspect I find a bit ...
104
votes
3
answers
120k
views
F# List.map equivalent in C#?
Is there an equivalent to F#'s List.map function in C#? i.e. apply a function to each element in the list and return a new list containing the results.
Something like:
public static IEnumerable&...
104
votes
1
answer
1k
views
MbUnit under Linux, used within an F# project?
I tried asking this on the gallio-users list, but the question failed to appear (Google Groups says the post was successful). I suppose the list might be moderated by someone who does not read his ...
103
votes
6
answers
20k
views
How can I use functional programming in the real world? [closed]
Functional languages are good because they avoid bugs by eliminating state, but also because they can be easily parallelized automatically for you, without you having to worry about the thread count.
...
99
votes
1
answer
18k
views
What the difference between a namespace and a module in F#?
I've just started learning F# (with little prior experience with .NET) so forgive me for what is probably a very simple question: What the difference between a namespace and a module in F#?
Thanks
...
98
votes
7
answers
13k
views
When are higher kinded types useful?
I've been doing dev in F# for a while and I like it. However one buzzword I know doesn't exist in F# is higher-kinded types. I've read material on higher-kinded types, and I think I understand their ...
94
votes
5
answers
19k
views
F#: let mutable vs. ref
First, I acknowledge the possibility that this question could be a duplicate; just let me know.
I'm curious what the general "best practice" is for those situations when mutability is desired. F# ...
94
votes
5
answers
15k
views
When to use a sequence in F# as opposed to a list?
I understand that a list actually contains values, and a sequence is an alias for IEnumerable<T>. In practical F# development, when should I be using a sequence as opposed to a list?
Here's ...
93
votes
8
answers
19k
views
F# explicit match vs function syntax
Sorry about the vague title, but part of this question is what these two syntax styles are called:
let foo1 x =
match x with
| 1 -> "one"
| _ -> "not one"
let foo2 = function
...
93
votes
8
answers
184k
views
What are the benefits of using C# vs F# or F# vs C#? [closed]
I work for a tech company that does more prototyping than product shipment. I just got asked what's the difference between C# and F#, why did MS create F# and what scenarios would it be better than C#...
92
votes
5
answers
15k
views
How do I use Travis-CI with C# or F#
Travis CI continuous integration service officially supports many languages, but not C# or F#.
Can I use it with my .net projects?
89
votes
2
answers
13k
views
What is the equivalent in F# of the C# default keyword?
I'm looking for the equivalent of C# default keyword, e.g:
public T GetNext()
{
T temp = default(T);
...
Thanks
87
votes
1
answer
4k
views
Async POST fails on WP7 and F#
When I do let! read = from.AsyncRead buf in F#, it blocks and doesn't return until the TCP socket is dead. Why? And how do I fix it?
Its code:
module StreamUtil
open System.IO
/// copy from 'from' ...
86
votes
5
answers
29k
views
F# defining/using a type/module in another file in the same project
This will hopefully be an easy one. I have an F# project (latest F# CTP) with two files (Program.fs, Stack.fs). In Stack.fs I have a simple namespace and type definition
Stack.fs
namespace Col
...
84
votes
4
answers
6k
views
Is it possible to write a JIT compiler (to native code) entirely in a managed .NET language
I'm toying with the idea of writing a JIT compiler and am just wondering if it is even theoretically possible to write the whole thing in managed code. In particular, once you've generated assembler ...
82
votes
4
answers
49k
views
Call F# code from C#
I am playing around with F# and C#, and would like to call F# code from C#.
I managed to get it to work the other way around in Visual Studio by having two projects in the same solution, and adding ...
81
votes
4
answers
11k
views
Use of `inline` in F#
The inline keyword in F# seems to me to have a somewhat different purpose than what I'm used to in e.g. C. For example, it seems to affect a function's type (what are "statically resolved type ...
79
votes
5
answers
43k
views
What is the F# language created to accomplish?
I have noticed more and more a growing number of resources for developing applications using the F# programming language and the question came to mind of what the F# language was created to accomplish....
78
votes
2
answers
13k
views
Best way to condense a list of option type down to only elements that are not none?
I'm unexpectedly having a bit of trouble with going from a list of 'a option down to a list containing only the elements that are Some.
My initial attempt was:
let ga = List.filter (fun xx ->
...
78
votes
1
answer
6k
views
Application architecture/composition in F#
I have been doing SOLID in C# to a pretty extreme level in recent times and at some point realized I'm essentially not doing much else than composing functions nowadays. And after I recently started ...
76
votes
11
answers
9k
views
What are practical uses of applicative style?
I am a Scala programmer, learning Haskell now. It's easy to find practical use cases and real world examples for OO concepts, such as decorators, strategy pattern etc. Books and interwebs are filled ...
75
votes
9
answers
21k
views
Explaining pattern matching vs switch [closed]
I have been trying to explain the difference between switch statements and pattern matching(F#) to a couple of people but I haven't really been able to explain it well..most of the time they just look ...
74
votes
3
answers
21k
views
Pattern matching on the beginning of a string in f#
I am trying to match the beginning of strings in f#. Not sure if I have to treat them as a list of characters or what. Any suggestions would be appreciated.
Here is a psuedo code version of what I ...
73
votes
10
answers
22k
views
F# performance in scientific computing
I am curious as to how F# performance compares to C++ performance? I asked a similar question with regards to Java, and the impression I got was that Java is not suitable for heavy numbercrunching.
...
72
votes
4
answers
7k
views
What are advantages and disadvantages of "point free" style in functional programming?
I know that in some languages (Haskell?) the striving is to achieve point-free style, or to never explicitly refer to function arguments by name. This is a very difficult concept for me to master, ...
72
votes
4
answers
16k
views
Why does the power operator in F# only work for floating point numbers?
I have never seen a language have exponent or power operator only taking floating point numbers?
For example:
2 ** 2 throws an error The type 'int' does not support any operators named 'Pow'
Are ...
71
votes
3
answers
15k
views
Does (or will) C# include features for side-effects verification? [closed]
I know C# is getting a lot of parallel programming support, but AFAIK there is still no constructs for side-effects verification, right?
I assume it's more tricky now that C# is already laid out. But ...
69
votes
6
answers
46k
views
How read a file into a seq of lines in F#
This is C# version:
public static IEnumerable<string> ReadLinesEnumerable(string path) {
using ( var reader = new StreamReader(path) ) {
var line = reader.ReadLine();
while ( line != ...
68
votes
31
answers
13k
views
Handy F# snippets [closed]
There are already two questions about F#/functional snippets.
However what I'm looking for here are useful snippets, little 'helper' functions that are reusable. Or obscure but nifty patterns that ...
68
votes
4
answers
5k
views
Why is F#'s type inference so fickle?
The F# compiler appears to perform type inference in a (fairly) strict top-to-bottom, left-to-right fashion. This means you must do things like put all definitions before their use, order of file ...
67
votes
2
answers
18k
views
F# vs OCaml: Stack overflow
I recently found a presentation about F# for Python programmers, and after watching it, I decided to implement a solution to the "ant puzzle" on my own.
There is an ant that can walk around on a ...
66
votes
1
answer
3k
views
How to marshal multi-dimensional arrays
We have some interop code that involves matrices. I was trying to call the native DLL and for the most part it works very reliably.
I am relying on the default marshalling by .net, avoiding unmanaged ...
65
votes
14
answers
39k
views
Units of measure in C# - almost
Inspired by Units of Measure in F#, and despite asserting (here) that you couldn't do it in C#, I had an idea the other day which I've been playing around with.
namespace UnitsOfMeasure
{
public ...
65
votes
1
answer
15k
views
What are the differences between in .fsx, .fsi and .fs file in F#?
So I'm starting to learn F# from the tryfsharp.org and I'm using VS2013. What are the differences of the .fs (source), .fsx (script) and .fsi (signature)?
63
votes
3
answers
14k
views
When should I use let, member val and member this.?
F# has many different ways to define variables/members in types. When should I use let, member val and member this. in F#, and what is the difference between them? How about static and mutable members?...
63
votes
3
answers
40k
views
C# / F# Performance comparison
Is there any C#/F# performance comparison available on web to show proper usage of new F# language?
63
votes
2
answers
8k
views
Is F# really faster than Erlang at spawning and killing processes?
Updated: This question contains an error which makes the benchmark meaningless. I will attempt a better benchmark comparing F# and Erlang's basic concurrency functionality and inquire about the ...
61
votes
7
answers
41k
views
What's a functional replacement for if-then statements?
I've been learning F# and functional programming and trying to do things the functional way. However, when it comes to rewriting some code I'd already written in C# I get stuck at simple if-then ...