Meaning of keyword “in” in F#

in is a hangover from F#’s OCaml roots and it specifies bound variables, which are subtly different to variable scopes. Think of variable binding as follows; You have an expression: first + ” ” + second As it stands first and second are unbound – they don’t have any fixed values – so that expression … Read more

How do I customize output of a custom type using printf?

It looks like the Right Way to do this in F# 2.0 is by using the StructuredFormatDisplay attribute, for example: [<StructuredFormatDisplay(“hello {a}”)>] type myType = {a: int} In this example, instead of the default {a = 42;}, you would get hello 42. This works the same way for object, record, and union types. And although … Read more

How does F#’s async really work?

A few things. First, the difference between let resp = req.GetResponse() and let! resp = req.AsyncGetReponse() is that for the probably hundreds of milliseconds (an eternity to the CPU) where the web request is ‘at sea’, the former is using one thread (blocked on I/O), whereas the latter is using zero threads. This is the … Read more

Resources for 2d game physics [closed]

Here are some resources I assembled a few years ago. Of note is the Verlet Integration. I am also including links to some open source and commercial physics engines I found at that time. There is a stackoverflow article on this subject here: 2d game physics? Physics Methods Verlet Integration (Wikipedia Article) Advanced Character Physics … Read more

Object-oriented programming in a purely functional programming context?

The disconnect you see is not of FP vs. OOP. It’s mostly about immutability and mathematical formalisms vs. mutability and informal approaches. First, let’s dispense with the mutability issue: you can have FP with mutability and OOP with immutability just fine. Even more-functional-than-thou Haskell lets you play with mutable data all you want, you just … Read more

Functional equivalent of decorator pattern?

In functional programming, you would wrap a given function in a new function. To give a contrived Clojure example similar to the one quoted in your question: My original drawing function: (defn draw [& args] ; do some stuff ) My function wrappers: ; Add horizontal scrollbar (defn add-horizontal-scrollbar [draw-fn] (fn [& args] (draw-horizontal-scrollbar) (apply … Read more

Handling Null Values in F#

For some reason (I haven’t yet investigated why) not (obj.ReferenceEquals(value, null)) performs much better than value <> null. I write a lot of F# code that is used from C#, so I keep an “interop” module around to ease dealing with null. Also, if you’d rather have your “normal” case first when pattern matching, you … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)