Lukas Domagala

  Home  |   Contact  |   Syndication    |   Login
  6 Posts | 0 Stories | 8 Comments | 0 Trackbacks

News

I have joined Anti-IF Campaign
Subscribe in a reader

Tag Cloud


Archives

Post Categories

F#

While I was building the position heuristic function for Connect Four I ran into an interesting gotcha with F# pattern matching. Lets see if you see it before I tell you what it is: let rec heuristic (positions: (int * int) list) (pos: int*int) = match positions with | [] -> 0 | position::_ -> 1 + (heuristic (List.tl positions) pos) | _ -> heuristic (List.tl positions) pos Looking at it, it seems the code should tell me how often value is in position, right? Well it doesn’t! And there is...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

I ran into some rather interesting numbers while trying to optimize my Connect Four implementation. Try to guess what this code will print out: let test= let stop1 = Stopwatch.StartNew() let list = [1..1000000] let bla = list |> List.fold (fun state x -> state + x) 0 stop1.Stop() let stop2 = Stopwatch.StartNew() let seq = seq{1..1000000} |> Seq.fold (fun state x -> state + x) 0 stop2.Stop() let stop3 = Stopwatch.StartNew() let arr = [|1..1000000|] let arr1 = arr|> Array.fold (fun state...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Last time we saw how to implement the basic miniMax algorithm, this time we will continue by designing game board representation. Basically I want to start out with the “simplest thing that might possibly work” and optimize from there. The simplest thing to use for this in F# is a 2 dimensional list. The problem is that we get some really bad performance for random access into them, because unlike C# Lists, called ResizeArray in F#, they really are represented by lists internally. To be precise they...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Ok, so do you have any idea what happens when you evaluate this? printfn "%d" -Int32.MinValue;; Well I would have guessed I´d get Int32.MaxValue, but well I was wrong. Actually it overflows again and prints Int32.MinValue. Interesting behavior that drove me mad while i was trying to implement Alpha-Beta pruning. There is a simple reason this happens: “The Int32 value type represents signed integers with values ranging from negative 2,147,483,648 through positive 2,147,483,647.” – MSDN Ok so there...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Lately there has been a lot of buzz about functional programming, mostly because it is supposed to be the cure to all of our concurrency troubles. The answer to this from MS has been to productize F#, a functional, object oriented language, running on .Net . There have been a lot of great blog posts and articles about F# in the internet, so if you are looking for a basic introduction this is not really the place. This series is supposed to fill in the whole i saw while searching for F# content. It...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Coding would be the right answer I guess, but more about that later. I will be starting out this blog with a totally useless post just to try out the GWB blogging software, so if you are reading this spare yourself the pain... Other then that I will soon start with a series on F# programming and hope to continue bringing in some .Net content. Cheers to you all and please don't flame a new blogger to much;) Technorati Tags: .Net,F#,FSharp...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati