1303 ms·
.NET Fiddle adds F#
- agentultra 13y agoI found F# to be rather neat. This is a great way to see for yourself.
- JeremyMorgan 13y agoI've done very little but it seems really concise. I like that. One place some predict it will emerge is in the Web API arena, and I could totally see that happening.
- dyml 13y agoWhy? What makes it better than C# in web Web API area? (honest question)
- bjg 13y agoType providers for one: http://msdn.microsoft.com/en-us/library/hh156509.aspx http://msdn.microsoft.com/en-us/library/hh156509.aspx http://channel9.msdn.com/posts/Tomas-Petricek-How-F-Learned-to-Stop-Worrying-and-Love-the-Data http://channel9.msdn.com/posts/Tomas-Petricek-How-F-Learned-...
- _random_ 13y agoAnything specific on F# applied to Web API?
- bunderbunder 13y agoF# has asynchronous workflows, which is a nice API for task parallelism built on computation expressions, which are sort of tamed monads. That edge dulled quite a bit with C# 5.0 and async/await, though.
- MichaelGG 13y agoIn my own tests, F# will require about 1/20th of the type annotations of C#. It offers a near superset of functionality, so you don't lose anything (except a bit on the tooling side of things). The lightweight syntax, easy handling of functional features, nesting of code - it ends up leaving you with far less code that has less bugs by default. MS describes F# as excelling at "programming in the small" - the line-by-line, char-by-char code is simply far superior to using C#. Just type inference alone is huge - C# is embarrassingly bad at type inference, and it's partially due to the complexity in their codebase in implementing it properly. At the moment, MS seems to have sort of backed off on enhancing C#. There's so many tiny things in F# that just make the code easier and less bug prone. For instance, being able to nest code. Suppose I want to read an integer out of a querystring, and on failure provide a default. Idiomatically, in C#: int age; if (!int.TryParse(qs["age"], out age)) age = -1; In F#: let age = try int qs.["age"] with _ -> -1 Or lets say I have some intermediate variables. In C#: int age; var parts = String.Split(bla, ","); if (parts.Length == 0) age = -1; else age = int.Parse(parts[0]); I've introduced a useless local var, parts, for no reason other than needing it in computing age. In F# (and avoiding pattern matching just to demonstrate): let age = let parts = String.Split(bla, ",") if parts.Length = 0 then -1 else int parts.[0] The intermediate binding, is not available outside it's scope. That's far cleaner, and quite commonly useful. Top level functions are handy. Being able to make useful lambdas without specifying the types is super useful. Many of my functions have a nested helper function which makes things cleaner. Places where I don't want to add a full utility function, but I don't want to repeat code. You can do it in C#, but it's ugly. In F# it's natural. Array/list comprehensions. In C#: var res = new List<int>(); using(var reader = cmd.ExecuteReader()) { while(reader.Read()){ res.Add(reader.GetInt32(0)); } } In F#: use reader = cmd.ExecuteReader() let res = [ while reader.Read() do yield reader.GetInt32(0) ] Pattern matching is well covered, and F# Active Patterns are just awesome, because you can customize your own destructuring for arbitrary objects. The list just goes on and on, lots of things in F# that are just so right, so easy, so trivial. Custom operators, tuple handling. I'm not even touching on the larger things, like Type Providers, records, sum types, or the fact that F# has monad syntax that's flexible, instead of C# building specific monads into the language. Heck, the F# compiler is far more advanced and produces faster code in many cases. And the fact that you can manually make it inline code is also a nice perf win you simply cannot get with C#. I recently started working on a project that uses C#, and it's just such a pain. Death by a thousand cuts. There's no reason to use C# over F#. Even if you only use F# as a light-syntax-C#, you're better off. The only real objection is hiring, in an enterprise scenario. For any serious project where the code is the product (versus the code being an artifact of just solving a business problem), I don't believe you can hire any good programmer that cannot deal with F#. (I think that hold for most languages, in general.) Unfortunately, people don't seem to believe that, and somehow think they're going to hire really smart people, but these people aren't going to be able to learn a different language.
- ponzao 13y agoOutside of web development any ideas what I could use it for (I am on Linux so it should run on Mono)? I've done quite a lot of web development on the JVM with Clojure, Scala and Java and would like to try to do something totally different with F#.
- BrokenEnso 13y agoLinux install instruxtions are at the F# website[1]. As for what you can use it for... anything you can use C#/mono for? [1] http://fsharp.org/use/linux/ http://fsharp.org/use/linux/
- ponzao 13y agoI have it installed and I've even dabbled with it a bit, but I am looking for some task where it would shine compared to JVM languages.
- zequel 13y agoCan anyone comment how F# compares to other functional languages? Just curious.
- the1 13y agolearn haskell because it's harder.
- throwaway344 13y agoF# is very un-functional in many ways. Immutable variables are the default but mutable variables are made with just the "mutable" keyword. There are also lots of imperative control structures, like while, and for. Those two combined means that imperative algorithims typically have two distinct translations into F#. First you can translate it literally, where F# looks like a slightly more verbose version of Python. Second you can exploit all the functional features of F#, and using immutable variables, recursion and pattern matching. F# also has extensive support for OOP, and uses it where OCaml-ers might use modules or functors. In that way, F# can be a sort-of stepping stone between the imperative, OOP C# to more functional features of F#.
- UK-AL 13y agoThe idea is that it is a functional first programming language, but allows you to use imperative or OO styles when the problem suits it.
- tucaz 13y agoThe OOP and imperative capabilities also make it easier for people coming from this kind of programming style to learn F#, such as myself. At first you write imperative F# to get used to the language and it's lack of verbose signs such as (, ; etc and hopefully you will be able to write more idiomatic/functional F# as your skill improves.
- mmavnn 13y agoUn-functional might be a bit misleading for an ML-based, default immutable language. Impure might be slightly more accurate. Having seen F# written by C# coders who've just learnt the syntax, and haskell programmers who are having to work in a .net environment, I'd say F# does a fairly good job of supporting both. It does make some trade offs to allow easy interop with the rest of the .net world (it's type system is much less powerful than Haskell, Scala or (especially) Idris) but depending on your environment that can be out weighed by the massive scale of the .net ecosystem, easy interop with your existing .net code and very, very good tooling.
- refactormonkey 13y agoSmall interruption. Looks like scaling to 2 servers on Azure to handle extra traffic crashed the original one.
- el_tone 13y agoAzure will reset your VMs when you update their configuration. Normally this involves a rolling reset but as you only have one instance this was not possible.
- refactormonkey 13y agoThanks for the info. I thought changing Scale would keep original server and just add new ones. But I guess it is a bit more intrusive.
- refactormonkey 13y agoShould be back up now. Mostly... If you get page not found, new DNS record didn't propogate yet. You can still use dotnetfiddle-prod.cloudapp.net or 191.234.40. Sorry for interruption. Lesson learned.
- physicslover 13y agoI would like to see an interactive loop to fsi. Seems like you could use websockets for this.
- refactormonkey 13y agoYeah, we are looking into it. Interactive provides great information to see what is really going on.
- AltGr 13y agoF#'s big brother, OCaml, has this: http://try.ocamlpro.com http://try.ocamlpro.com The best part is that since OCaml can compile to JS, it's completely offline !
- latkin 13y agoAnother option you might want to look at is http://www.tryfsharp.org/Create http://www.tryfsharp.org/Create Runs code locally via Silverlight.
- JeremyMorgan 13y agoI'm getting my fizz buzz on.
- virtualwhys 13y agoCool to "see" F# in action. Like the union types, but not so much the list operations; seems more natural to: [1;2;3;4] filter isEven sum vs. List.filter isEven [1;2;3;4] |> List.sum in Scala it's: List(1,2,3,4) filter isEven sum Of course I'm not familiar with F# so don't know all of the WIN within (Type Providers, for example, are very impressive, would love to see that on the Scala side of the fence one day).
- throwaway344 13y agoIn F#, most pipelined operations are expressed using the pipeline operator all the way. [1; 2; 3; 4] |> List.filter isEven |> List.sum That way you maintain the same operator order as you do in Scala, while maintaining some consistency with currying. In addition, you can add other functions really simply while still maintaining the order. [1; 2; 3; 4] |> List.filter isEven |> List.sum |> printfn "%i"
- virtualwhys 13y agoInteresting, in Scala you do: list filter isEven foreach println Which is, IMO, quite elegant, but then again I'm used to Scala and not yet at all familiar with F# and the reasoning behind the syntax.
- anonymoushn 13y agoList(1,2,3,4) filter isEven sum println error: type mismatch; found : Unit required: Numeric[?] List(1,2,3,4) filter isEven sum println ^
- virtualwhys 13y agoI didn't write what you wrote ;-) foreach takes a collection and applies some function (in this case println). I've actually had a use case for what you're trying do, so created an extension method on Any, which means you can then do, on Any-thing: (list filter isEven sum).echo I also hate typing "println". "echo" I can bang out instantly, and can do so on any expression, before or after its definition.
- balsam 13y agoAnybody managed to install F# on Ubuntu? There are recommended steps [0] but they've never worked for me even on a new 13.04 (& later) image on DigitalOcean. [0] http://fsharp.org/use/linux/ http://fsharp.org/use/linux/
- profquail 13y agoI use F# on Windows and FreeBSD, but I've used it on Ubuntu a few times before for testing. Here's how I did installed it: git clone git://github.com/mono/mono.git cd mono autogen.sh sudo make install clean cd .. git clone git://github.com/fsharp/fsharp.git cd fsharp autogen.sh sudo make install clean It takes a while to build Mono from scratch, but this way has always worked for me.
- balsam 13y agoYour steps are almost the same as the one I linked. But I tried them, just in case. And it still does not build. The fsharp build fails with some error about casting types. Do you have version details?
- profquail 13y agoTry building the 'fsharp_30' branch instead. The master branch just switched over to F# 3.1, so its possible they haven't worked out all of the bugs for every possible system yet. When I ran F# on Ubuntu before, it was on the x86 version of 12.04 LTS. I used whatever the latest version of Mono was; I don't remember specifically, but it was almost certainly one of the 3.2.x versions. Would you mind posting the build output from your F# build that fails (e.g., to pastebin or Gist)? I can forward it along to the right people so it gets fixed. Or, post it as a Github issue: https://github.com/fsharp/fsharp/issues https://github.com/fsharp/fsharp/issues