News for hackers. Stuff that matters.
Re:Revenge of the Types by thelinked on Sunday August 24, 2014 @05:53PM (#8219790)
Re:Revenge of the Types by Dn_Ab on Sunday August 24, 2014 @07:27PM (#8219993)
pjungwir's example code is actually really close to what you'd see in F#. In F# you'd typically write it in a more functional way with say a recursive inner function but I'll leave it imperative for clarity's sake:

    [<Measure>] type s
    [<Measure>] type m
    [<Measure>] type km  

    let mtokm (x:float<m>) = x * 1.<km>/1000.<m>
   
    //the types of g and ground are inferred
    let drop g ground (x0:float<m>) =
         let mutable x = x0  //type inferred here
         let mutable t = 0.0<s>
         let mutable v = 0.0<m/s> 
         let dt = 0.01<s>

         while x >= ground  do
            v <- v + g*dt
            x <- x + v*dt
            t <- t + dt 
         t  

   > drop -10.0<m/s^2> 0.<m> 50.<m>  
   val it : float<s> = 3.16
Re:Revenge of the Types by hoggle on Sunday August 24, 2014 @06:14PM (#8219845)
I've got to confess that I love how the design of MS languages regularly exposes my ignorance towards them.

Edit: removed unrelated Wikipedia article (Unit Type)

Re:Revenge of the Types by karavelov on Sunday August 24, 2014 @06:21PM (#8219860)
Unit type is completely different concept in the functional languages. It does not track units and measures.
Re:Revenge of the Types by hoggle on Sunday August 24, 2014 @06:27PM (#8219876)
Oh my, thanks for the heads-up I guess it's too late to post on HN. Time to go to bed :)