Slashdot Mirror


Inside Microsoft's New F# Language

robyn217 writes "There's a new language being formed in the bowels of Microsoft. Recently I got word that the language F# (pronounced F Sharp) is nearing workable stages at Microsoft Research. So, I went in for a look-see. What I found was an interesting blend of imperative (Java, C#) and functional languages(it's ML-based, too!). It looks pretty enticing to me from a computer science perspective, but I'm not sure it would fly in the professional market. I can see the ease of development that a language loosely based on ML would bring, but I can't see coders switching over in droves since it's a tough learning curve." Our previous story on F#.

18 of 606 comments (clear)

  1. It's OCaml for the .NET CLR... by Anonymous Coward · · Score: 4, Informative

    It's OCaml for the .NET CLR. Not a new language. Nothing to see here. Move along.

    1. Re:It's OCaml for the .NET CLR... by Junks+Jerzey · · Score: 3, Informative

      Yes, but the problem with most ML implementations is that they are academic toy languages. You can't do anything useful with them because you can't connect them to real I/O

      In all honesty, what are you talking about? You can pick up OCaml right now and I/O is just fine. Period.

      if you can you can't distribute the code as noone else has the environment

      So everyone has to use C forever and ever?

    2. Re:It's OCaml for the .NET CLR... by Zeinfeld · · Score: 2, Informative
      In all honesty, what are you talking about? You can pick up OCaml right now and I/O is just fine. Period.

      Yeah, yeah and you could write programs in ANSI Pascal, problem was you could not do it without a lot of hassle.

      Under dotNET there are no second class languages (well apart from C++), they all can access the same runtime. That is a major advance. OK you could write to the Java bytecode but anything other than Java will always be a second class language in that environment.

      --
      Looking for an Information Security student project suggestion?
      Try http://dotcrimeManifesto.com/
    3. Re:It's OCaml for the .NET CLR... by bratmobile · · Score: 2, Informative

      C++ is not a second-class citizen under .Net. In fact, Managed C++ is one of the best-supported languages. Managed C++ can be used to generate, or access, nearly every aspect of the Common Language Infrastructure / Common Type System.

      It is, arguably, the most expressive language in .Net, because it can generate/access all managed language features, as well as still having full support for all unmanaged features -- normal C++ classes (malloc/free/new/delete semantics), templates, etc. Managed C++ is designed to be the ultimate bridge language, between the existing world of unmanaged C/C++ and managed .Net classes.

      Now, in some ways, that's not necessarily a good thing. C# restricts you from doing some stupid things, or at least you must knowingly enable unsafe operations (using the /UNSAFE command line argument, and then you STILL have to use the "unsafe" keyword in source code). But, still, Managed C++ gives you an amazing degree of interoperability with both worlds, and it's seamless.

    4. Re:It's OCaml for the .NET CLR... by TheGrayArea · · Score: 2, Informative

      >>Under dotNET there are no second class languages (well apart from C++), they all can access the same runtime
      Not true. You can use the Managed C++ extensions to access everything in the runtime. Heck, you can even host the runtime yourself if you wish.
      Check out:
      http://msdn.microsoft.com/library/default.asp?url= /library/en-us/vcmex/html/vcconMCOverview.asp

      --

      This space for rent.
    5. Re:It's OCaml for the .NET CLR... by MillionthMonkey · · Score: 3, Informative

      (DISCLAIMER: I didn't write this myself- we were having an email conversation about F# today at work, and this is what our CEO had to say about it. I got his permission to repost his email here but he insisted on editing a few comments disparaging to Microsoft because he wants to encourage them to keep working on it.)
      --snip--

      F# seems to be based very closely upon ocaml, which was the language that I used for day to day work before Java.

      I think ocaml is a fantastic language, although, like everything, it had a few significant problems five years ago:
      - obscure [ F# could fix this ]
      - not as many libraries as a mainstream language [ F# could fix this. ]
      - not great module support - if module A depends on B, then B cannot depend on A.

      Disclaimer: everything I say comes from personal, but old, experience, and a cursory look at the F# web site.

      Interesting properties of ocaml:
      1) Functions are first class objects. E.g..
      let add x y = x+y;
      let add3 = add 3;
      print (add3 4);
      -> 7
      2) Polymorphism works well. So you could define a function that takes an array of objects x and a function that maps x to y, and produce an array of objects y. Eg
      let a = [| 5,6,7 |] // an array of integers
      print (Array.map add3 a)
      -> [| 8,9,10 |]
      3) Type checking is strong, compile time, and usually implicit. All types in the examples above are deduced correctly. Disadvantage: You can't have operator overloading, even for the plus sign... so + means integer addition, and +. means double addition.

      4) You can return multiple values from a function
      let cis t = (cos t,sin t);
      let (ct,st) = cis (PI /. 2.0);
      print ct;
      -> 0.0

      5) Variables are final by default, but can explicitly be made not-final. There are also control structures that make many things that one does in Java by changing variables simpler. This can make debugging simpler, but takes a while to get used to.

      6) There is some very powerful pattern matching code - imagine a more powerful case where you could say

      int x;
      Point y
      switch (x,y) {
      case 7,null: do this
      case 4,Point(3,?) : do that
      case x,Point(y,x) : print y
      default:
      }

      [ Actually, there is no direct concept of null, but that is not the point. ]

      I particularly liked ocaml as it allowed imperative features, had GC and exceptions, and had a very good compiler that produced fast code. I was very impressed by the French academic group that made it and supported it.

      [ Note examples are not valid ocaml - they are ocaml features with a javaified syntax to make them easier to explain, and besides, I have not used the language for years. ]

      The current F# implementation does not sound very efficient for a variety of reasons. It is also not nicely polymorphic in the same way that ocaml is. This defeats a lot of the point of it. They need support for generics in the VM for these to work well. There is a different group at MS research working on this - I would be delighted if both the F# project and the generics project make it into the mainstream.

      It is not clear how well the ML view of types will match up with the C# view of types. ML programming feels different to Java programming, and this could make the .NET library matching clumsy. But if they could make it work, then that could get rid of two of the biggest perceived issues that have prevented widespread adoption of ocaml.

      --snip--

  2. I like the idea by Anonymous Coward · · Score: 5, Informative

    My first year CS classes were taught in ML. It's a very potent language. I especially liked the type inference system. What other languages do in templates comes naturally in ML. Our CS prof gave us an example of Quicksort in 3 lines of readable code. As an academic language ML has problems interfacing with real life systems. OcaML was a step in the right direction and MS is building F# on it. I'll certainly try this one.

  3. Re:first post by Mocenigo · · Score: 2, Informative
    f # souns really good next to g

    Not really. F# and g form a dissonance, called a minor second. It happens though that I like g-f#, a major seventh. But maybe a listen to too much contemporary music.

  4. Caml by Eudoxe · · Score: 2, Informative

    F# looks like OCaml. You can have a look on the libraries already present for this fabulous language on the hump http://caml.inria.fr/humps/index.html

  5. Re:Filters by zero_offset · · Score: 2, Informative
    Insightful? Please.

    First of all, I've been working in a probably-much-larger (one of the largest) financial institutions for six years, and I see C# all over the place. So much for anecdotes.

    Second, I've been working for various large companies since Internet-based e-mail started, and I've never seen anything that would filter F#. So much for speculation.

    Now if I just had some moderator points. :P :)

    --

    Slashdot quality declines as the number of hot grits posts decreases. - Provolt's Law, Apr-09-2005

  6. Haskell next? by axxackall · · Score: 5, Informative
    While I like ML (whole family) so much more than any imperative legacy (Java, C++, C, Perl), I see the main problem that any ML has with for modern RAD and with scripting is its static typing. And that's why I like (more than ML) Haskell - it's dynamically typed and thus it's much more appropriate both for operating scripting and for big app RAD.

    Until today, both ML and Haskell had a common problem: a lack of commercial and real world interest in it and therefore a lack of real-world libraries and supporting frameworks. But now things are going to be changed.

    First Ericson came with Erlang, an excelent essence of FP, LP, scripting and networking. Now M$ (I know - evil, but anyway) came with F# bringing OCaml to the real world saving from being forgotten somewhere in Inria.

    What next? I think that would be Haskell, the language even more suprior to ML, with already OOP, Parallel and Cuncurrent extensions. Also I like its Functional-Logical dialect - Curry. But who will bring it to the real world? IBM?

    --

    Less is more !
    1. Re:Haskell next? by KieranElby · · Score: 5, Informative

      I wouldn't bet against Microsoft bringing Haskell to the real world - their research department (which would put many universities to shame) has some top Haskell people, such as Simon Peyton Jones.
      There's some interesting papers by him over here.

    2. Re:Haskell next? by milesegan · · Score: 4, Informative

      Haskell is most certainly not dynamically typed. Like ML, it is a statically typed language with a compiler that does type inference at compile type. You don't usually have to manually declare types but you still have to get them right at compile time. There are some differences between ML's type system and Haskell's but they're basically the same animal.

      ML and Haskell differ mainly in that ML is an eager language, which evaluates all arguments to functions before evaluating the function. Haskell is a lazy language which delays evalution of function arguments until their values are needed.

      Erlang, on the other hand is dynamically typed.

  7. Re:Funny quote of the day by Eudoxe · · Score: 3, Informative

    In France, students learn Caml during their first year before school of engineer. Maybe this will help the devel of ML in industry.

  8. The D Programming Language by Anonymous Coward · · Score: 1, Informative

    is the true successor to C and C++. See digital mars.

  9. Re:Filters by alexjohns · · Score: 2, Informative
    OK, I see your large financial institution, and raise. I work for Wells Fargo, in one of their divisions. 130,000 employees. I doubt it's the largest one in the world, but still pretty large. Back to you. Call?

    We have a common Tech Library (in San Fran) where you can check out books. I see 3 C# books in the online listing. I imagine some division somewhere is toying with it. Everyone I know about in the company is doing C/C++/Perl/Java.

    I was a sysadmin for a few years. I've seen several instances where filters on "f-junk", where -junk is some subset of characters like '!@#%*', were implemented. Don't know what country/jurisdiction you live/work in, but not only is it a politeness issue, it's a sexual harassment issue. Just because some PHB somewhere decides to let the f-bomb slip in an all-employee email doesn't mean the company wants to open itself to a lawsuit. I never implemented one myself, but I've been on mailing lists/fora where the necessity and implementation details were discussed. (Also, internally, we've had emails from the Exchange people about inappropriate language. I don't know specifically that they filter on that word, but I'm pretty sure there's a flag somewhere that gets raised. Not sure what happens. No desire to find out, I like my job.)

    So then, if you had moderator points what would you moderate me as? Offtopic? Nope, on-topic. Flamebait? Nope, don't think I qualify. Troll? No, not even. Best you could do is overrated, I guess. The coward moderator's choice (since it doesn't get meta-moderated.) I always like the guys who down-moderate you because they disagree with you.

    HAND.

  10. Re:This isn't all apparently... by MisterFancypants · · Score: 3, Informative
    OTOH, there is a right way and a wrong way of approaching this. In the example of DBC, MS would do good by providing an Eiffel implementation for their CLR. In the example of F#, MS would be more correct to introduce Scheme and LISP dialects rather than invent their own.

    Bertrand Meyer is one of the biggest .NET boosters on the planet, and he already oversaw a port of Eiffel to .NET. This was available like a year ago.

    There's also a Scheme compiler, called Hotdog, with a .NET backend:

    Keep in mind that F# is but one of MANY language research projects going on at Microsoft Research, and there are many more going on at other sites that Microsoft is tangentially involved with.

  11. Re:Gee Flat by Rich0 · · Score: 2, Informative

    Uh - I'm a string player, and if you asked me to play either I'd stick my finger in exactly the same place.

    They are in fact the same note. Granted, no string player hits any note dead-on, so maybe some tend to hit a pitch a little higher or lower when going up or down a scale, but it has nothing to do with the notes actually being different.