F# is really a nice language and an easy way to get in to functional programming. I have known about its existance for years but never tried it until a couple of months ago. Starting by scripting is the best way to get started.
http://brandewinder.com/2016/02/06/10-fsharp-scripting-tips/
You can start scripting with f# on Linux.
Then create a file :
hello.fsx:
#!/usr/bin/env fsharpi
let hello what = printfn "hello, %s" what
hello "world"
Then make it executable and run it with:
./hello.fsx
Or if not executable
fsharpi hello.fsx
If you are on windows fsharpi = fsi
I wrote this on my phone so I haven't tried it in real life. :-)
Not a lot comparing to c#. But more than Haskell or Ocaml (at least in London). I really hope it will be more used in the industry. I like it much more than Scala and would like to see more companies using it (hire me!). See here for testimonials
So I'm new to .NET Core (and even newer to F#), having come from a Unix background, and currently working on a Windows-based .NET stack, I'm not sure how to understand things like this:
Unsurprisingly, the nomenclature is insanely confusing, but isn't F# just another CLR language, and covered by the umbrella of CoreCLR?
Unfortunately I don't have any beginner tutorials to recommend, there are probably some good ones out there. http://fsharp.org/ is a good place to start; you can also look at https://fsharpforfunandprofit.com/learning-fsharp/
As to your specific problem, fsharp code can run like python does, that is, compiling it on the fly from source. It can also run in a precompiled form (as a .net assembly packaged in a .dll or .exe). <EntryPoint> is only relevant for the latter.
You could start writing your program in python style like this:
// wc.fsx open System open System.IO
let text = File.ReadAllText("sample.txt") printfn "%s" text
I didn't actually count the words because you probably want to fill that in :) Anyway, you could run this program with "fsharpi wc.fsx" on a mac or "fsi wc.fsx" on windows. If "sample.txt" does not exist it will throw an exception.
If you wanted the precompiled .net assembly form, the source would look like this:
// wc.fs open System open System.IO
[<EntryPoint>] let main argv = let text = File.ReadAllText("sample.txt") printfn "%s" text 0 // return an integer exit code
You then build that with "fsharpc wc.fs" (on a mac) or "fsc wc.fs" on windows. On windows you can run the resulting .exe directly, on a mac you need run it with mono, eg "mono wc.exe".
Fsharpi works like the the "python" command with no arguments, it starts interactive mode, you can paste code in there and see what Fsharp does with it.
It helps to have a good editor to start. Visual Studio is obviously good for windows, and Xamarin is decent for mac. I haven't extensively used any of the other editor plugins.
If I'm going to be completely honest, I have a difficult time imagining why you would want Scala for .NET, when .NET is the native platform of F#. As much as I like using Scala professionally given the reflexive and pervasive choice of the JVM for server-side work, I prefer OCaml as a language, and F# is OCaml's .NET cousin, although, like C#'s evolution away from Java, F# has changed quite a bit from its OCaml roots—not necessarily in bad ways.
TensorMetric, how did this lose a big order of Surface tablets exactly? What did the ordering party go with instead and why?
Seems lot a FUD clouding the argument for MS to extend F# support here which probably isn't helping the cause especially this unsubstantiated statement from over two years ago: https://stackoverflow.com/questions/23355973/is-it-possible-to-use-f-with-the-new-windows-universal-apps/32000593#32000593
>>BTW. A major client of ours wanted tens of thousands of tablets and they took Microsoft tablets off the table because they don't support F#.
So what is the best tablet to buy that "supports F#" right now? How does the perf-per-watt-hour on Android compare to the prevailing Windows non native F#-based apps using older compiler tech?
> However F# keeps you in the windows ecosystem
Not necessarily. I haven't spent as much time with it as I'd like, but it worked pretty well from what I could tell. It's even in Debian, so it passes their reasonably strict free software requirements.
You can already run F# on Linux and Mac with Mono (see http://fsharp.org/use/mac and http://fsharp.org/use/linux) and the support for writing mobile apps using Xamarin (Android and iOS) is probably better than what you get on Windows Phone. So, I don't think Microsoft would be an issue. Also, the F# community is very open-source friendly.
I'd say that the language you choose does not matter much, if you are interested in basic functional concepts (those are the same everywhere). But this only goes as far - once you get into type classes or monads (in Haskell) or functors (in OCaml), you are really learning specific of that particular language. At that point, I think it's more fun to play with F#, which gives you access to lots of powerful libraries.
@ OP: Don't be scared of new languages and techs because they are new. Try them out, develop a quick spike, and decide based on experience, not fear of the unknown.
You don't have to use .net core if you want to try F# out. Not even fsharp.org's install instructions suggest using it yet; they suggest Xamarin's mono repo instead, among other options. Since you're just interested in trying it out and don't care, I'd say do what the "Option 9" section says and just install it with Nix. No issues with it shitting up your system that way, and easy removal if you don't like it. I tried using the Xamarin repo but it ended up breaking when I upgraded to Debian testing, so I think I'll try the Nix route next time I get the urge to use it.
(You could also just install from your distro's repo, if you don't care about getting what's likely to be an older version.)
Still, I was able to spend a bit of time with F# before the update, and it seemed pretty nice. If you like anything about OCaml or other ML languages, there's a good chance you'll find something to like with F#. It has a "modern ocaml" feel, sort of like how Clojure has a "modern lisp" feel. I noticed there's still some rough edges with Linux usage, mostly REPL issues, but nothing major.
The author is 'she' ;-).
I'm pretty sure you could solve the problem in any programming language that's out there. As for the Star Wars one, F# has a few nice things that make it easy to write (powerful type inference, REPL, etc.) but some other languages have them. The article uses R type provider (for typed access to ggplot), which is something that only F# can do (with this degree of integration), so that bit would have to be done differently. As for the James Bond post, that one uses type providers (HTML type provider) which is really neat and does not have equivalent elsewhere.
So, you can of course do everything in any other language, but I think F# has some nice features that make it a lot easier and lead to more correct & efficient code. (Good resource here is the F# testimonials page.)
/r/fsharp
I recently got convinced to learn F Sharp.
Visual Studio 2013 Community Edition supports F Sharp: https://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx
I'm not sure how it handles Windows Form as I only see an option to make an F Sharp console application.
this page has a decent list: http://fsharp.org/guides/web/
i played a bit with Suave last summer and enjoyed it. depending on what your needs are some may be more appropriate (e.g. features or ease of getting stood up).
Getting started with F# on Mac: http://fsharp.org/use/mac/
My suggestion is Option 2
https://suave.io/ is a very nice (IMO) web framework for writing functional code for a micro services. I would also stay away from .Net Core in general since the F# integration isn't quite there yet, namely it's missing debugging and a few language features, like Type Providers. Speaking of Type Providers, I would suggest this library for your ORM needs with MySQL: https://github.com/fsprojects/SQLProvider
big fan of F# here. you can definitely learn it as a first language, although you may quickly get into the deep end. the community, however, is very friendly, much more so than many other languages.
as for resources, i like the Programming F# book out on O'Reilly a lot. i am not too keen on the APress one (black and yellow cover). a good list of books is here, including a new one covering mobile stuff in F#.
http://fsharp.org/about/learning.html
as for if it's the best choice, not knowing your background (e.g. math, science, business, the arts), one of the more common first languages to learn is python. i came to F# from python (after ~10 years), FWIW, and now prefer F# over python. you can quickly get up to speed in programming concepts and then move into other languages.
no idea myself, but you might kind of be looking in the wrong place.
I'd suggest finding some existing math libraries/projects and looking at their todos/roadmaps/etc and asking those contributors what help they need
check out the open source libraries listed here. Seems like the biggest is and most general is math.Net but it won't necessarily be pure F#, as it's primary target is all of .Net. If you want to restrict yourself to F# only though there's stuff there to work on.
Even if you'd rather stick to yourself and make your own library as an F# learning exercise, perusing the list of opensource and commercial libraries might be of benefit just so you know what's out there, both to know what areas are untackled (and might be primed for some harder to code original contributions), and which areas are well represented (for example, for times you're more interested in learning how F# works and would like to see how others answered approached the same problem), and perhaps which areas are well represented commercially but lack open source alternatives (if that happens to align with your personal vision of ideal beer)
Myself I'm new to F# and functional and despite being a programmer of some years have yet to see any way I can contribute anything not already done better by many others. Getting involved in FAKE would be awesome for me but I'm not DevOps so much in my current gig so whatev. Good luck and best wishes to your future maths and F# explorations. Have fun :)
You are indeed correct.
// * Summary *
BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19041.508 (2004/?/20H1) Intel Core i7-4790K CPU 4.00GHz (Haswell), 1 CPU, 8 logical and 4 physical cores .NET Core SDK=3.1.201 [Host] : .NET Core 3.1.3 (CoreCLR 4.700.20.11803, CoreFX 4.700.20.12001), X64 RyuJIT DEBUG DefaultJob : .NET Core 3.1.3 (CoreCLR 4.700.20.11803, CoreFX 4.700.20.12001), X64 RyuJIT
| Method | Mean | Error | StdDev | |------- |---------:|----------:|----------:| | testA | 1.811 ns | 0.0071 ns | 0.0060 ns | | testB | 1.367 ns | 0.0112 ns | 0.0105 ns |
source:
// Learn more about F# at http://fsharp.org
open System open BenchmarkDotNet.Attributes open BenchmarkDotNet.Running
let sq x = x * x
// int -> int -> int let testA x value = let sqx = sq x compare value sqx
// int -> (int -> int) let testB x = let sqx = sq x fun value -> compare value sqx
let curriedA = testA 2 let curriedB = testB 2
type Bench() = class [<Benchmark>] member this.testA () = curriedA 6 |> ignore [<Benchmark>] member this.testB () = curriedB 6 |> ignore end
[<EntryPoint>] let main argv = BenchmarkRunner.Run<Bench>() |> ignore 0 // return an integer exit code
Well is just .NET all the way down. So is not much to wrap. Or look at this:
http://fsharp.org/guides/data-access/
--
Is important to note that what is practical or what is idiomatic is not always the same. So, DB acces is as good as with C#, or you can spice it a bit the F# way. But if time is critical, you can do that later.
This is how I start with F#.
Since you've posted this in the F# subreddit, I assume you're interested in using F# to write your game. In which case, I'd recommend two resources:
Unfortunately, the guy making that series stopped after five videos, and videos 4 and 5 contain some concepts that could have really used a bit more explanation in video #6. But it's a great introduction to F#, and it even uses a simple text adventure game as the example!
BTW, the tools I'd recommend you use are:
If you have more questions, especially of the "how do I get F# or these other tools installed?" variety, the first person you should ask is the professor who assigned you the homework. Then ask here, or on Stack Overflow.
Good luck, and have fun!
No worries about sounding a bit critical. We're really trying to make the getting started story easier, but it's not the simplest thing to do!
Can you try downloading the basic template from http://fslab.org/download/ and see if that works for you?
If no, can you open an issue with more details (at http://github.com/fslaborg/FsLab) or perhaps ask on the #fsharp Slack channel? (See http://fsharp.org/guides/slack). I'm often there and would be happy to help!
> Considering how young Clojure is as a language it's amazing how widely used it is today.
Yes but the same is true of F#. Traders buying or selling coal, oil, gas or carbon credits in Europe are almost certainly running F# code on their desktop. Customers getting insurance quotes from one of the world's largest insurance companies are having it calculated by F# code. The world's largest marine broadband provider uses OCaml. MATLAB and Mathematica are both partly written in OCaml. The Louvre Abu Dhabi is being architected using F#.
Clojure and F# have been leapfrogging each other over the past few years in terms of popularity in the job market.
Then consider how language ideas are seeping into mainstream languages. Java and C# got garbage collection and lambdas from Lisp, granted, but they didn't take homoiconic syntax or macros. Then they took generics (which is parametric polymorphism from ML) and C# took type inference and async from F# (which took it from OCaml).
So the race is not yet run. Both Clojure and F# are seeing far more use today than any FPL before them. I'm just saying ML is definitely going to beat Lisp, that's all. :-)
// * Summary *
BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19041.508 (2004/?/20H1) Intel Core i7-4790K CPU 4.00GHz (Haswell), 1 CPU, 8 logical and 4 physical cores .NET Core SDK=3.1.201 [Host] : .NET Core 3.1.3 (CoreCLR 4.700.20.11803, CoreFX 4.700.20.12001), X64 RyuJIT DEBUG DefaultJob : .NET Core 3.1.3 (CoreCLR 4.700.20.11803, CoreFX 4.700.20.12001), X64 RyuJIT
| Method | Mean | Error | StdDev | |------- |----------:|----------:|----------:| | testA | 0.0061 ns | 0.0039 ns | 0.0036 ns | | testB | 3.8540 ns | 0.0444 ns | 0.0393 ns |
source:
// Learn more about F# at http://fsharp.org
open System open BenchmarkDotNet.Attributes open BenchmarkDotNet.Running
let sq x = x * x
// int -> int -> int let testA x value = let sqx = sq x compare value sqx
// int -> (int -> int) let testB x = let sqx = sq x fun value -> compare value sqx
type Bench() = class [<Benchmark>] member this.testA () = testA 2 6 |> ignore [<Benchmark>] member this.testB () = testB 2 6 |> ignore end
[<EntryPoint>] let main argv = BenchmarkRunner.Run<Bench>() |> ignore 0 // return an integer exit code
Good to know, thx. So the last time I tried I went by this page's instructions: http://fsharp.org/use/linux/
First, if you happen to know, does this still install Mono? My understanding is that Mono is being replaced with .NET Core's CLR...?
Second, (and this is almost a separate topic), can I produce native executables? If you have any links I could read I'd be happy to do some learning on this.
Thanks in advance for any assistance!
I'm doing a similar project with F# (data sci and ml) and find it very good.
Check out this very helpful O'Reilly guide to 'Analyzing and Visualizing Data with F#' : https://fslab.org/report/
Also check out these: http://fsharp.org/guides/data-science/ http://fsharp.org/guides/machine-learning/
For Deep Learning there is CNTK however the .NET API is very new and not as friendly as the Python API.
You should get on the F# Slack. You need to be a member of the F# Software Foundation, but membership is free. They have a #beginners channel that's great for questions like yours.
Although you can build F# 4.0 from source, it looks like the binaries for OS X and Linux aren't out yet.
F# is a statically typed .Net language just like C#, and F# code is instantly accessible from C#. To get started, from your C# project simply add a reference to your F# library, just as you would with a C# library. If you're designing an F# component to be consumed by multiple languages you should also check out the F# Component Design Guidelines: http://fsharp.org/specs/component-design-guidelines/
you might be interested in learning that f# is open source and cross-platform. you can download the free xamarin ide to start playing around in fsi, f#'s equivalent to haskell's ghci.
http://fsharp.org is an excellent resource and will get you going on any platform.
i do highly recommend the haskell tutorial "learn you a haskell for great good".
Actually some people are doing noticeably well. Have a look at some of these testimonials. These people aren't deluded or just using it for the hell of it or because they think it's "cool". While this link is just for F#, I'm sure users of other FP languages would also have similar claims.
In addition to C#, I think the author of the blog post is also missing out on F#. Everything that you described (Mac/Linux compatibility, open source compiler, etc.) is all already available through F#.
From http://fsharp.org/specs/component-design-guidelines/ - referenced in your link:
> Do use classes to encapsulate mutable state, according to standard OO methodology.
Yikes. Why not just eliminate mutable state altogether?
For one thing, if we're going to use mutable state, why use F# in the first place?
Admittedly .Net interop usually requires mutation for side effects to take place. But I would think that you would ought to limit where that takes place in your app to a controlled area, similar to how Redux in JavaScript-land manages state changes. F# seems strikes me as a reasonable choice with this kind of architecture.
I think if you mix mutable style and immutable style together, mutation has a tendency to spread across your codebase until you lose the primary benefit of functional style, namely the greater ease with which you can reason about your code. (As well as other benefits such as safe parallelization and so on.)
I would never recommanded Fsharp to my alter ego as a starting language instead of Python. But...
Fsharp is really beautiful even if you consider the fact that it is getting uglier when using C# libraries. Similar to Clojure when it meets Java. :)
> but haven't found any decent resources for learning F#
Some resources for F#:
> I think it's a bit of a shame as F# is a very nice language, but it is clear that it hasn't managed to get a lot of traction so far.
I already pointed you at ~50 counter examples here.
The official F# website has some links to consulting companies. You can see if any of them might be able to help - http://fsharp.org/consulting/.
If not, you can also try asking on the official F# open forum - https://groups.google.com/forum/#!forum/fsharp-opensource.
Great info and tips. Thank you. I know some of those algorithms like K-Means Clustering and Newton's Convergence Algorithm and some of the others I've heard of. I may need to brush up on my statistics and my linear algebra. I was thinking of starting with F# because I already know it and it seems like F# is good for data science (http://fsharp.org/guides/data-science/index.html). I'll give some of these other algorithms a shot and try to get a copy of that book.
Thanks, that helps a lot. I come from a .NET background and I found this page: Guide - Data Science with F#, that I might use as a starting point since I already know some F#. I've actually taken that Coursera class and learned a lot from it. I didn't realize that data science and machine learning are much in the same (or at least share the same algorithms).
Have you considered F#(http://fsharp.org/)? It's a functional language but unlike C#, it's open sourced and is cross platform comptabile. Since you mentioned that you liked C#/.NET, it should be a relatively easy transition. And if you are working in academia, you might find that F# is fairly popular in those circles already.
> A few months of C++ likely is not going to get you very far in terms of algorithmic trading. I'd recommend a higher level language to start with
I completely agree. I'd also like to point out that the other "conservative" choices, Java and C#, aren't significantly more powerful than C++. IMO you should be looking at functional languages. Here's some feedback from happy F# users, many with lots of C++ experience.
F# isn't my personal choice as I prefer to stay off of .NET and don't like the multiparadigm aspects of F#, Ocaml and Scala, but those testimonials are great for showing the strength of functional programming.