F# on Jupyter

Learn how to set up and use F# on Jupyter notebooks. Explore F# beyond data science with interactive coding examples.

3 min read 546 words

This blog is part of FSAdvent F# calendar 2019.

Jupyter has been around for ages. It's one of the data scientist's favorite tools. Kind of the best thing to write words, equations, and results in the best possible manner. F# is and was a poster child for .NET to do Data Science. I never liked the poster child part, but still, it is what it is. I'll come to that a little later on.

F# was also not far behind. My first encounter with a Jupyter-like thing for F# is "try F#". Old Silverlight version. And then data scientists in the community haven't stayed behind. They created super awesome iFSharp binding for Jupyter.

Recently, things moved forward and .NET Core started Jupyter officially. For C# and F# both.

I wanted to try, so I was going through Scott Hanselman's blog for setup and details. There was a simple C# example and then an F# example with CHARTS. I was like, please don't do this. F# is good for Data Science, but it is also good as a General Purpose language. And every time people show an example of F# with Data Science, I feel like they are typecasting the language. I feel like we are telling Jim Carrey to do only comedy when he shines like anything in Eternal Sunshine of the Spotless Mind.

I think with Jupyter support, we can do way more things than Data Science. Let's first go through the setup part.

You can follow the setup details written up in Scott Hanselman's blog, or here are simple steps for installation from that blog.

  • Install Anaconda for simpler Python version management
  • Open Anaconda terminal. Or check if conda is working if it is in the path.
  • Install global dotnet try. dotnet tool install --global dotnet-try
  • If already installed, then try to update it by reinstalling it
  • Check if Jupyter is working. jupyter kernelspec list
  • Install .NET kernel. dotnet try jupyter install
  • Check the kernel list again. jupyter kernelspec list

Now, the real fun starts. Go to this repo and clone it.

Go to the folder and run either jupyter notebook or jupyter lab. I personally like the latter.

Here I partially converted a very famous series, The Designing with Types from Scott Wlaschin, to Jupyter. It is like a live blog. And fun thing—if you go to GitHub and click one of the files, it will execute things for you on GitHub as well.

It might not be perfect because blogs are not written with Jupyter in mind, but still, it is way better for learning new concepts. Reading and trying out things right there and then makes things more fun and easier to grasp.

Scott was nice enough to permit me to use one of his series.

If you like how it looks, you can always give a PR for the remaining series and also update the examples with more Jupyter-friendly code.

It is my take on a new tool. We should use this to learn F# as a General Purpose language, not only as a Data Science language.

There is a whole Python book converted to read with Jupyter. I guess we can also have one, can't we?

Frequently Asked Questions

What is F# on Jupyter and why would I use it?

F# on Jupyter is an integration that allows you to write and execute F# code directly in Jupyter notebooks, combining the interactive notebook environment with F#'s powerful functional programming capabilities. It's useful for data science, general-purpose programming, and interactive learning because you can write code, documentation, and see results all in one place.

How do I install F# support for Jupyter?

First install Anaconda for Python management, then open the Anaconda terminal and run `dotnet tool install --global dotnet-try`. Next, install the .NET kernel with `dotnet try jupyter install`. Finally, verify the installation by running `jupyter kernelspec list` to confirm the F# kernel appears in your available kernels.

What are the basic setup steps to start using F# in Jupyter?

After installing Anaconda and the .NET kernel, navigate to your project folder and run either `jupyter notebook` or `jupyter lab` to launch the Jupyter interface. Then you can create new notebooks or open existing F# notebooks to start writing and executing code interactively.

Is F# on Jupyter only useful for data science?

No, while F# is often associated with data science, Jupyter support opens F# to many other use cases including general-purpose programming, educational content, and interactive documentation. The notebook format is beneficial for any domain where you want to combine executable code with explanatory text and results.

Can I share and run F# Jupyter notebooks on GitHub?

Yes, when you upload F# notebook files to GitHub, you can click on them directly in the repository and GitHub will render and execute them for you. This makes notebooks excellent for creating interactive tutorials, live blogs, and educational content that others can learn from without setting up their own environment.

Share this article