Introducing F#-M

Andrii Kurdiumov
7 min readNov 17, 2023
Learning is hard ;) Photo by Ariel Castillo

Why programmers speak English only? Okay, I get that we have largest market with English speaking people, but why we teach children in foreign language?

Okay, that’s enough for the hook, so I can start talking about my pet project — multilingual fork of F# where you can have keywords in your own language. My idea is that English speaking word have programming on the easy level, where they not only barely understand what’s going in the code, but also have lot of associations to understand how internally things working.

Let me give some examples:

Let’s pretend that we live in alternate reality when Ukrainians pioneer computers and all programming languages are based on Ukrainian instead of English.

So we will target very simple constructs like якщо/тоді. This construct looks like this

якщо умова тоді
вираз

Construction якщо/тоді used for the conditional execution of the expression specified by вираз. Condition specified by the умова expression.

As you may see, there a lot of indirection during explanation of concepts. Most of the readers internalize if/then concept in their own language, but not what programmers mean when they write if/then. And then explanation hidden behind foreign words. When teacher will use colorful analogies from real world to simplify things when in English they almost should not do that, since explanation will be literally if and then. I would say that Dictionary, List, primitive operations like copy, reverse, add, etc. All of them are simple words, but furthermore they are foreign words.

My point is not that we should drop English and start programming in native languages, but rather that first programming language can be presented to the children in their own native tongue. And we have that earlier, I and probably many other developers from Europe seen such programming languages during their childhood. Logo for example, even Scratch I think looking into same direction, albeit on even earlier audience.

There claims across practitioners that once you master one language, you can switch them as you like. So why not start learning concepts in the language which is easier to teach? If you think learning foreign language was easy for you, please be honest with yourself. I’m almost sure it was hard. So maybe real claim was “once you spent 10 years mastering one language, can switch them as you like”. If you still think that original claim is valid, then I don’t see why not teach in language closer to yours.

Other angle which I consider, is that children from poor or socially vulnerable families. Maybe it make sense smooth learning curve a bit. Usually it’s harder for them meet all demands, and maybe if unbundle learning programming and learning English in same package would be beneficial.

What i did

When I was in school, math, physics, geography, biology, chemistry, all kind disciplines were available for me in my own language. And even programming! Why now landscape is different? Yes, programming language now is much more complicated, beast then earlier, and have tooling for another dialect is complicated thing. IDE or some editor support, and why even bother, if every child can learn Python or Unity? So creation of ecosystem and tooling is HUGE and nobody should try that.

I have questions to myself about ecosystem. And here what I did to answer them:

  • How about editor support? This is actually interesting case on open source community, F# ecosystem being reliant on CoreCLR and MSBuild + being super friendly, allows me to have full Visual Studio support. Not important for teaching, but custom fork of Ionide was completely possible for me, and only laziness and some dependencies logistics prevent me from doing it.
  • Where can I get libraries? I would say, once you have great editor/IDE you can either rename all public interface for already existing libs, or provide aliases for types/functions in F#. Examples for Ukrainian and Russian can be found here. I plan to add Kazakh, Turkish, Polish, Czech, Deutch, Dutch, Spanish. But if you think you want to see your language, let’s get in touch.
Example in Spanish
  • I don’t want editor, I want online editing experience. Okay buddy. Fairly trivial you can make fork of Fable REPL and host it online. Not repl? but notebooks? What kind of notebooks, will Binder works? Or Polyglot Notebooks if you preferred kind of notebooks. That’s doable too.
Polyglot notebook with F# in Ukrainian
  • To try and see how language can look, I create small application where you can change names of keywords and interactively take a look at the result.
  • Where is content? That most problematic part. Somebody has to write it. I’m not professional educator, and for this idea to took off, somebody have to write lot of content for different age groups. That’s not trivial amount of work. I have no easy solution for this.
  • Nice idea, but why F#? Umm, that’s only language where I find supportive community which helps me to implement it. When I have something to show, it’s easier to present idea to people. It is practical idea now, not hypothetical. If you have other language in mind where you want that to happens, let’s talk, we can work on this idea together! Python definitely looks like good candidate.

Bilingual approach

Initially I thought about replacing existing keywords with different names in other language, but after looking at the lexer design, I understand that I can support both languages at once, and this gives me interesting properties. I take existing code and gradually move it from English to your target language. Initially it would be a mess, but this is how we actualyl speak among themselves. We use a lot of anglicism, sometimes it’s become funny when you try to explain how things working to regular people, like business mans, analyst, product managers. If you are insensitive to other people, or rather don’t know how to call things in your own language, then why you so picky about keywords which you as developer will see :)

How hard was that?

Okay, this looks like a lot of work. Probably it is, but most of work was done actually in the F# compiler, and only change which I have to do is augment lexer approximately like this.

Below is actual location of the file where to apply change. Mostly it was it. Seriously! Yes, I do have to dance with compilation and distribution parameters, but plain F# compiler easily hackable and you can trivially use it.

To produce bits after the fork. This is a bit of magic command. So I think it is worth share it.

Build.cmd -pack -ci /p:OfficialBuild=true /p:PublishWindowsPdb=false /p:VisualStudioDropName=dummy -c Release

Also, I rename FSharp.Compiler.Services assembly to FSharp.Compiler.Service.Ukrainian so when loading kernel for Polyglot Notebooks, it would not conflict with existing F# kernel, because I have fork of F# .NET Interactive kernel essentially.

Other big chunk of work was made F#-M support for Rider. It was rather hard, and not adequately documented. But I was given helping hand. and because it require me to fork Rider’s fork of F# it was fun :) Fork of Fork was new experience for me. Also I have to touch some Java code in Idea colorization. It was hard for me, cannot deny. But with guidance it take two sessions over call IIRC. Not months of work.

Linguistic problems

When playing with this idea, mostly it was working fine for core language. But for some languages I encounter problems which make life complicated.

First problem is that sometimes identifiers in codebase conflict with keywords in other language. Notable example is klass in German/Turkish. F# codebase love use klass as identifier :) this is easiely solvable problem — just give identifier new name and if you are lucky you may try upstream changes. I did not try that, be ready for rejection.

Second kind of problem much more complicated. When we have word which change meaning in the languages. For example do in Polish is analog for to and how we have a problem. I don’t want disambiguate what token do mean based on context, since that require changes in the compiler. This would be hard, and requre maintaining fork. For these problems I think I need help of linguisist or other professionals who love their language, so they can find appropriate alternative.

And all these is just from handful set of European languages. What about other families? Chinese, Arabic, Hebrew, dozens African and Indian languages which I do not know about. What about Tamil? Will this approach works? Where it fails, is there something interesting to learn about programming languages?

Call for arms

Actually this is call for keyboards, if you think that this is bad pedagogical idea, let me now. I truly want understand why this is bad from teacher’s perspective. I you teach Computer Science, I probably should state caveat emptor. I’m more interesting in non-science education. Likely colledge level, or even school-level. Something for students to even get what programming is. Even procedural programming sometimes is hard to internalize. Anyway even so, I still would love to hear pragmatic critique where this idea will start cracking.

If you want send me kind words, I appreciate it too :)

If you have some ideas what can be improved, that would be totally awesome to hear.

Personal thanks

I owe a lot for implementation of this idea to Vlad Zaritovskiy @vzaritovskii . He always try to answer my silly question about F# compiler and ecosystem. Also special thanks for Alex Berezhnykh aka DedSec256 who babysit me when we try to hack Rider to support F#-M.

Links

--

--

Andrii Kurdiumov

Math lover, lost in the woods of software development