With Halloween tomorrow, now is the perfect time to take a look at phantom types in F#. So what are phantom types? Think of them as a way to embed a constraint into the type system of a language. Here’s a great example of using them [...]
|
||||||
|
With Halloween tomorrow, now is the perfect time to take a look at phantom types in F#. So what are phantom types? Think of them as a way to embed a constraint into the type system of a language. Here’s a great example of using them [...] So how can we match over abstract data types in a more palatable manner?
Active Patterns
The pattern matching syntax of F# will change the way you write code. Of all the reasons to begin the move from VB to F#, the declarative style of pattern matching is reason number one. The days of the “nested if” are numbered and blood pressures [...] We may not have proper type class constraint support in F#, but we can still make sure our ‘square’ function doesn’t blow up at runtime.
Passing the Dictionary of Operations Explicitly
In the comments of the last post, Cale Gibbard noted that the monad abstraction is pointless unless you can write code that works against the abstraction, instead of a particular instance. Haskell let’s you write work with the monad abstraction through the use of type classes. This ad hoc form of polymorphism [...] Although not strictly necessary, to be a good F# programmer you pretty much have to learn Haskell. It reminds me of the relationship between VB and C#. Sure, you don’t have to learn C#, but you miss out on so much good knowledge and know how if you don’t. Without C#, you can [...] When learning something new I like to focus on the things that I can’t do with my current programming skill set. The first time I skimmed through Expert F# I realized there’s a whole lot of skill set that I don’t have. Of particular interest was the concept of monads/computations/workflows. I can’t [...] To generate a list of Fibonacci numbers, we created a generator class that emulates the behavior of the c# yield statement. We’ll expand on this generator in another blog to enable us to write LINQ methods, but for right now we’ll use if for a similar task, generate a list or primes.
|
||||||
|
Copyright © 2010 Do Loop Until You Die - All Rights Reserved |
||||||