After I got out of this talk on F# I ran into my superior (most of the crew of ILM Services was at the Norwegian Developers Conference) and he mentioned that he had just seen a talk on Q# which is for Quantum Computing which involves computations I really don't understand wherein qubits (quantum bits) are the core building block. Like F#, Q# comes from Microsoft and while quantum computing is not really feasible yet, Microsoft is nonetheless trying to pioneer the space. Apparently there was an analogy made in that talk about how train tracks were proactively laid to cross the mountains between France and Switzerland before there was yet a train powerful enough to make that trek. F# might as well be as Q# for me as I know I'll never work with it professionally. I kind of wondered if I could even "hang" in this talk and indeed I had some trouble. Some of emulation of Dungeons & Dragons dice rolls in code showed the number of the same kind of dice (six-sided, twenty-sided, etc.) followed by an asterisk and then followed by a function call wherein the six or the twenty for the number of sides of the dice was handed in. I was immediately suspicious that this wasn't really emulating dice rolling as in the case of rolling two six-sided dice you could only get doubles, right? The value returned from the function at the right would be multiplied by the number two at the left via the asterisk in the middle and you could get 2, 4, 6, 8, 10, or 12, yes covering the whole of the range, but not really representing the reality that it is much harder to roll a 2 (the odds are one in thirty-six) than it is to roll a 6 across two dice. When I tried to be smart and point out this flaw it was just pointed out to me in retort that I was reading the F# wrong and that the phenomenon that favors a likely landing in the center of a range was in operation. F# is not C# and the mathematical operators behave differently. The right side of the operation reruns a number of times dictated by the left side. Mathias Brandewinder went through some of the basics of F#. A discriminated union is kind of like an enum in C#. There is an old mantra in F# encouraging you to "make impossible states unrepresentable" and so in the live coding examples there were attempts to restrict what could be handed into certain things with discriminated unions. Something to think about is if you have two discriminated unions at a record, could there be any combinations of the two which should be disallowed. Don't ask me what to do about that problem however. This was all a bit over my head. Fable-Elmish, which sounds Dungeons & Dragonsesque, compiles your F# to JavaScript. It uses the Babel compiler to do so so the Fable part comes from Babel with a leading F for F#. Elmish implies the use of the Elm pattern which is also called MVU for (model-view-update). In MVU, messages send updates to models which in turn make their way into views. An application initializes by starting up a model and then there is an ongoing listening for messages.
No comments:
Post a Comment