You'll also notice this if you hover over the function in Visual Studio Code. This is known as the type signature of the function, a fundamental piece of F# that's key to understanding F# code. This states that toPigLatin is a function that takes in a string as input (called word), and returns another string. You may have noticed the following in FSI: val toPigLatin: word: string -> string If it doesn't start with a vowel, move that first character to the end of the word and add "ay" to it. If the first character in a word starts with a vowel, add "yay" to the end of the word. If you're not sure about what the code is actually doing, here's a step-by-step.Īs you can see, toPigLatin is a function that takes a word as its input and converts it to a Pig-Latin representation of that word. The at the end lets FSI know when the code is finished. This is because FSI allows you to enter multiple lines. Congratulations, you just wrote your first F# function in Visual Studio Code and evaluated it with FSI!Īs you may have noticed, the lines in FSI are terminated with. The function appears to be working as expected. You should see the following result: val it: string = "appleyay" Now, let's try with a vowel as the first letter. You should see the following result: val it: string = "ananabay" The FSI process evaluated the code you sent over.īecause what you sent over was a function, you can now call that function with FSI! In the interactive window, type the following: toPigLatin "banana".It sent the code you highlighted over to the FSI process.You'll notice a terminal window pop up on the bottom of the screen, and it should look similar to this: Once it's highlighted, hold the Alt key and hit Enter. Highlight the entire function (it should be 11 lines long). The next step is to evaluate it using F# Interactive (FSI). This function converts a word to a form of Pig Latin. Now add the following code to it: let toPigLatin (word: string) = NET Core scripting, navigate to the Explorer view in Visual Studio Code and create a new file. Once you've configured Visual Studio Code to use. You can write code in the editor before this point in time, but once this happens, everything has finished loading. This means Ionide has successfully loaded the project you just created. Once it completes, change directory to the project and open Visual Studio Code: cd FirstIonideProjectĪfter the project loads in Visual Studio Code, you should see the F# Solution Explorer pane on the left-hand side of your window open. NET CLI: dotnet new console -lang "F#" -o FirstIonideProject To create a new F# project, open a command line and create a new project with the. To begin, ensure that you have F# and the Ionide plugin correctly installed. Visit Ionide.io to learn more about the plugin. You can write F# in Visual Studio Code with the Ionide plugin to get a great cross-platform, lightweight Integrated Development Environment (IDE) experience with IntelliSense and code refactorings.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |