Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

Ryan Riley

Ryan Riley Ryan Riley

Niner since 2009

  • Windows Azure Storage: What’s Coming, Best Practices, and Internals

    Has there been any discussion about integrating encryption into the API or storage? That would really help in a lot of scenarios for financial or healthcare applications.

  • Rick Molloy: Actor-based Programming in C++ - Control Flow versus Data Flow

    Thanks for fixing that, Charles.

  • Rx Workshop: Introduction

    @aaron_brown99: I'm not sure if the challenges have changed, but some were presented at ALT.NET Seattle, and the code is available at http://rxworkshop.codeplex.com/.

  • Rx Workshop: Introduction

    Awesome! I was hoping you guys would post this. Looks like it has some excellent updates!

  • C9 Lectures: Dr. Don Syme - Introduction to F#, 2 of 3

    I agree, an in depth discussion between Erik and Don would be fun. I wouldn't mind seeing them point out the major differences between F# and Haskell, as well as how to write Haskell-esque F#. I would think we would see a lot of material similar to Matt Podwysocki's articles on monads. Smiley

     

    By the way, if you are interested in more videos, community, etc. around F#, please join Community for F# (http://c4fsharp.groups.live.com). We have Live Meetings every third Tuesday of each month at 12:00 pm EST. Details can be found on the Live Group (you'll have to join to see it though as Live Groups doesn't allow anything to be just public :-/). Hopefully Don will join us soon! Tomorrow we have Steffen Forkmann talking about Fake (F# make), Natural Spec, and Functional NHibernate.

  • First Look: Windows Phone 7 Series Hands on Demo

    While I have really enjoyed my iPhone, when the Zune HD came out, I thought to myself that Microsoft had just toasted Apple on UI/UX design. I was a little sad they didn't launch WP7 then, but the quality is apparent and should help make up ground over the next few years. Well done!

  • C9 Lectures: Dr. Erik Meijer - Functional Programming Fundamentals Chapter 12 of 13

    That will definitely be well-received! Thanks for presenting this fantastic series, Erik. Happy new year!

  • Peer to Peer Series Part 1: Intro to PNRP

    I'm having the same problem.

  • Brian Beckman: The Zen of Stateless State - The State Monad - Part 1

    Here's my solution to exercise 2 using F#:

     

    The type defs:

    type Rect =
        { Height: float;
          Width: float;
          Top: float;
          Left: float }
        with override r.ToString() = String.Format("Height: {0}, Width: {1}, Top: {2}, Left: {3}", r.Height, r.Width, r.Top, r.Left)
      
      (* StateBuilder Bounder *)
      let boundTree tree seed leftUpdater rightUpdater =
        let rec labelTree t updater =
          match t with
          | Leaf(c)      -> state { let! s = getState
                                    let (next, curr) = updater s
                                    do! setState next
                                    return Leaf(curr, c) }
          | Branch(l, r) -> state { let! l = labelTree l leftUpdater
                                    let! r = labelTree r rightUpdater
                                    return Branch(l, r) }
        exec (labelTree tree leftUpdater) seed

      type Rect =

        { Height: float;

          Width: float;

          Top: float;

          Left: float }

        with override r.ToString() = String.Format("Height: {0}, Width: {1}, Top: {2}, Left: {3}", r.Height, r.Width, r.Top, r.Left)

     

      type Tree<'a> =

        | Leaf of 'a

        | Branch of Tree<'a> * Tree<'a>

     

      // The show method already takes into account the tuples,

      // unlike the show method that is overloaded in the C# version.

      let show tree =

        let rec printTree tree level =

          let spacing = new string(' ', level * indentation)

          printf "%A" spacing

          match tree with

          | Leaf(label, contents) ->

              let labelString = label.ToString()

              printfn "Leaf: %s, Contents: %A" labelString contents

          | Branch(left, right) ->

              printfn "Branch: "

              printTree left (level + 1)

              printTree right (level + 1)

        printTree tree 0

     

    The state monad builder:

      (* StateMonad *)

      type State<'S, 'a> = State of ('S -> 'S * 'a)

     

      (* StateBuilder Bounder *)

      let boundTree tree seed leftUpdater rightUpdater =

        let rec labelTree t updater =

          match t with

          | Leaf(c)      -> state { let! s = getState

                                    let (next, curr) = updater s

                                    do! setState next

                                    return Leaf(curr, c) }

     

          | Branch(l, r) -> state { let! l = labelTree l leftUpdater

                                    let! r = labelTree r rightUpdater

                                    return Branch(l, r) }

     

        exec (labelTree tree leftUpdater) seed

     

      let eval sm s =

        match sm with

        | State f -> f s |> fst

     

      let exec sm s =

        match sm with

        | State f -> f s |> snd

     

    The demo tree:

    let demoTree = Branch(

                     Leaf("A"), 

                     Branch(

                       Branch(

                         Leaf("B"),

                         Leaf("C")),

                       Leaf("D")))

     

    The updaters and execution code:

    let leftBounder =

      fun (depth, rect) -> let newDepth = depth + 1.0

                           let multiplier = 2.0 * newDepth

                           ( (newDepth,

                              { Height = rect.Height

                                Width = rect.Width / multiplier

                                Top = rect.Top

                                Left = rect.Left + rect.Width / multiplier }),

                             { Height = rect.Height

                               Width = rect.Width / multiplier

                               Top = rect.Top

                               Left = rect.Left } )

     

    let rightBounder =

      fun (depth, rect) -> let newDepth = depth - 1.0

                           ( (newDepth,

                              { Height = rect.Height

                                Width = rect.Width * 2.0

                                Top = rect.Top

                                Left = rect.Left + rect.Width }),

                             rect )

     

    let initialDepth = 0.0

    let initialRect = { Height = 100.0

                        Width = 100.0

                        Top = 0.0

                        Left = 0.0 }              

    let ex2Seed = (initialDepth, initialRect)

     

    printfn "Bound tree to rects"

    let bTree = boundTree demoTree ex2Seed leftBounder rightBounder

    show bTree

     

    This works, but I imagine there must be a better way. I'm open to suggestions.

  • Brian Beckman: The Zen of Stateless State - The State Monad - Part 1

    "So... any solutions available for the exercises above?" <| Geez! Maybe I should look to see if pages of comments exist before displaying my stupidity to the world. Great work holoed!

See more comments…