This video provides a quick review of the important features in the F# language that are most relevant to this course and to mobile development, such as option types, discriminated unions, and pattern matching. It also covers some of the differences you might encounter.
- [Instructor] Some of you folks coming from a Xamarin background, could be missing some context with F# that you won't necessarily learn in an introductory class. So we've gathered a small assortment here. First, in F#, file ordering is important. A file can only reference a file that is physically located above it in the project structure. For example Agents.fs here, can reference Core.fs, but not UndoRedo.fs. The same is true within a single file. Code can only call code that is above it in the file.
For example, in this set here, postUndo could call postAdd if needed, but not postRedo. The reason behind this is so that the compiler is able to sort out the type inference for the full program more quickly. And it has two main benefits. First, you can't create a circular reference. This makes dependency charts and the general flow of an application much, much simpler. Second, it's very easy for a newcomer to the code to jump in. Either at the top line of the top file, or the bottom line of the bottom file.
Next, there's a lot of talk in the functional world about immutability in code. As you'll discover, mobile development in general, and the Xamarin flow in particular have been fairly heavily influenced by object oriented programming. This means we'll be using one little feature quite a bit. Mutable Assignment. This is done with the back arrow, as compared to using let and an equal sign. Record Types are a fantastic, lightweight structure. They're very similar to tuples, which are ordered, unnamed values. Here we have a triple containing a string, a color, and an integer.
Because these types are inferred on the go, and not declared upfront, The order of the types within the tuple must remain. Records on the other hand, have named, unordered values. In this case we're declaring a record type containing the same information. A string, a color and an integer. We're naming them this time, though. As name, color, and count. This means that we don't need to keep the information in a consistent order. In practice, it's more clear if you do, though. To use a record type that you've created, you'll work with record expressions.
The examples that we'll use in this course, all look like this first one. Where each name is associated with a value. But it's possible to simultaneously copy and initialize a new record by referring to another record. This will replace any values that are specified and copy any unmentioned values. So as an example here, blue7 will be a string blue, the color blue, and the integer seven. And red4 will be the string red, the color red, and the number four. Finally, records use structural equality, not reference equality.
This means that when trying to determine if two records are equal, F# will look to the contents of the records, not to their location in memory. So as an example, these two records on the screen will be shown as equal. In some languages they will not, because they have different physical locations in memory. Finally, you'll recall that F# is white space sensitive. Now, there are different kinds of white space. So where does F# fall in the epic Tabs vs. Spaces war? Very firmly on the side of spaces. In fact, tabs are an illegal character in the language.
If you try to use tabs, you will get an error. Xamarin Studio has a way to help you out, though. As long as we have it set, there's an option to convert tabs into spaces for all files. Go to Xamarin Studio, Preferences, Source Code, Code formatting, F# Files There's a Convert tabs to spaces check box here. You can either check this here, by unchecking the Use default settings, and making sure that this is checked, or by changing it within the text file options.
In either case, you'll definitely want to have this check box checked, for ease of coding during this course.
- Developing in F#
- Developing in Xamarin
- Developing in XAML
- Using Paket
- Creating an application
- Adding buttons and views
- Asynchronous workflows
- Adding a mailbox processor to an app
- Modifying the core code
- Adding a reply feature to an app