Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Learning F#

Learning F#

Scheduled Pinned Locked Moved The Lounge
learningcsharpphpwpfcom
50 Posts 23 Posters 7 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Josh Smith

    I've been spending some of my free time trying to learn about F# because it seems really interesting.  The problem is, the existing F# tutorials SUCK.  I think that the language tutorials provided by Microsoft were written by brainiacs in the Microsoft Research group, so it's not really helpful at all.  For example, I read that this:

    int -> int

    ...represents a function which takes and int and returns an int.  The problem is, the author failed to mention which "int" represents the return type and which the parameter type. :|  There's only one F# book out there yet, and all the reviews I've read of it say that it sucks too.  Come on MS, if you're gonna publicly announce[^] that F# is on the rise, at least give us some good introductory material first!! Don't make it so f#ckin hard for us! ;)

    :josh: My WPF Blog[^] Without a strive for perfection I would be terribly bored.

    B Offline
    B Offline
    bscaer
    wrote on last edited by
    #41

    Blanking out one letter of the F-bomb does not make it kid-sister-friendly. Please clean up your language.

    J 1 Reply Last reply
    0
    • B bscaer

      Blanking out one letter of the F-bomb does not make it kid-sister-friendly. Please clean up your language.

      J Offline
      J Offline
      Josh Smith
      wrote on last edited by
      #42

      bscaer wrote:

      Please clean up your language.

      :zzz:

      :josh: My WPF Blog[^] Without a strive for perfection I would be terribly bored.

      1 Reply Last reply
      0
      • J Josh Smith

        I've been spending some of my free time trying to learn about F# because it seems really interesting.  The problem is, the existing F# tutorials SUCK.  I think that the language tutorials provided by Microsoft were written by brainiacs in the Microsoft Research group, so it's not really helpful at all.  For example, I read that this:

        int -> int

        ...represents a function which takes and int and returns an int.  The problem is, the author failed to mention which "int" represents the return type and which the parameter type. :|  There's only one F# book out there yet, and all the reviews I've read of it say that it sucks too.  Come on MS, if you're gonna publicly announce[^] that F# is on the rise, at least give us some good introductory material first!! Don't make it so f#ckin hard for us! ;)

        :josh: My WPF Blog[^] Without a strive for perfection I would be terribly bored.

        S Offline
        S Offline
        Stuart Dootson
        wrote on last edited by
        #43

        Your head's really going to flip when you get to binary functions:

        int -> int -> int == int -> (int -> int)
        

        i.e. if

        plus x y = x + y
        

        then the expression

        plus 3
        

        is syntactically and semantically correct, and returns a function of type int -> int. And plus 3 5 is really (plus 3) 5. Learn Haskell[^] first, and then F#'ll be a piece of cake! But you'll miss cool features of Haskell like type classes and such like.

        J 1 Reply Last reply
        0
        • S Stuart Dootson

          Your head's really going to flip when you get to binary functions:

          int -> int -> int == int -> (int -> int)
          

          i.e. if

          plus x y = x + y
          

          then the expression

          plus 3
          

          is syntactically and semantically correct, and returns a function of type int -> int. And plus 3 5 is really (plus 3) 5. Learn Haskell[^] first, and then F#'ll be a piece of cake! But you'll miss cool features of Haskell like type classes and such like.

          J Offline
          J Offline
          Josh Smith
          wrote on last edited by
          #44

          Stuart Dootson wrote:

          Your head's really going to flip when you get to binary functions:

          Sounds like fun! You seem to know quite a bit about functional programming, so let me ask you a question. From a business app developer's perspective, what are the benefits of using a functional language like Haskell in a real world app dev scenario? I know that there is a lot of fervor around multi-core/multi-processor computing, but what else is there? I'm just looking for more fuel to add onto my F# fire. Thanks. :)

          :josh: My WPF Blog[^] Without a strive for perfection I would be terribly bored.

          S D 2 Replies Last reply
          0
          • J Josh Smith

            Stuart Dootson wrote:

            Your head's really going to flip when you get to binary functions:

            Sounds like fun! You seem to know quite a bit about functional programming, so let me ask you a question. From a business app developer's perspective, what are the benefits of using a functional language like Haskell in a real world app dev scenario? I know that there is a lot of fervor around multi-core/multi-processor computing, but what else is there? I'm just looking for more fuel to add onto my F# fire. Thanks. :)

            :josh: My WPF Blog[^] Without a strive for perfection I would be terribly bored.

            S Offline
            S Offline
            Stuart Dootson
            wrote on last edited by
            #45

            Josh Smith wrote:

            From a business app developer's perspective, what are the benefits of using a functional language

            Probably not a lot at present :-) - the frameworks and infrastructure are still aimed at imperative languages. I think it's more realising what's good about the functional approach, and applying that to programmiing with your favourite language. There are two big things to take from functional programming, IMO - referential transparancy (a.k.a no updateable state) and functions as first class objects. Once you catch onto referential transparency, you realise that it's often a lot easier to create a new object rather than try to modify an existing one, which leads you to define objects as immutable (i.e. after they're constructed, you can't modify them). Functions as first class objects...well, you already have that in C# with delegates, really - lambdas in C# 3.0 just make it even easier to do anonymous functions. It's the whole idea of providing customisation points by allowing a function to be passed into some generic code, rather than implementing as a class with virtual functions. The C++ STL does this nicely with some of its algorithms. e.g.

            template<class RandomAccessIterator, class Pr>
            void sort(RandomAccessIterator _First,
                      RandomAccessIterator _Last,
                      BinaryPredicate _Comp);
            

            You're passing in the sort criteria as a function. This is what enables 'iteration' functions like map, fold, filter etc in functional languages - you internalise looping within those functions by passing the loop body in as a (usually anonymous) function. Of course, there's lots of other good stuff in languages like F# and Haskell - partial function application (that's the plus 3 thing in my original reply), type inferencing,  algebraic data types, pattern matching, polymorphism with type classes to ensure type correctness (that's Haskell only, and is incredibly powerful). Anyway - I find direct use of functional languages best for prototyping some of the more theoretical things I do - parsing, tree and term rewriting...although I have written a simple, multi-threaded web server in Haskell (just for larks!) in about 150 lines of (commented) code. However, functional programming has made big changes in how I write my (C++) code, making it simpler, s

            J 1 Reply Last reply
            0
            • S Stuart Dootson

              Josh Smith wrote:

              From a business app developer's perspective, what are the benefits of using a functional language

              Probably not a lot at present :-) - the frameworks and infrastructure are still aimed at imperative languages. I think it's more realising what's good about the functional approach, and applying that to programmiing with your favourite language. There are two big things to take from functional programming, IMO - referential transparancy (a.k.a no updateable state) and functions as first class objects. Once you catch onto referential transparency, you realise that it's often a lot easier to create a new object rather than try to modify an existing one, which leads you to define objects as immutable (i.e. after they're constructed, you can't modify them). Functions as first class objects...well, you already have that in C# with delegates, really - lambdas in C# 3.0 just make it even easier to do anonymous functions. It's the whole idea of providing customisation points by allowing a function to be passed into some generic code, rather than implementing as a class with virtual functions. The C++ STL does this nicely with some of its algorithms. e.g.

              template<class RandomAccessIterator, class Pr>
              void sort(RandomAccessIterator _First,
                        RandomAccessIterator _Last,
                        BinaryPredicate _Comp);
              

              You're passing in the sort criteria as a function. This is what enables 'iteration' functions like map, fold, filter etc in functional languages - you internalise looping within those functions by passing the loop body in as a (usually anonymous) function. Of course, there's lots of other good stuff in languages like F# and Haskell - partial function application (that's the plus 3 thing in my original reply), type inferencing,  algebraic data types, pattern matching, polymorphism with type classes to ensure type correctness (that's Haskell only, and is incredibly powerful). Anyway - I find direct use of functional languages best for prototyping some of the more theoretical things I do - parsing, tree and term rewriting...although I have written a simple, multi-threaded web server in Haskell (just for larks!) in about 150 lines of (commented) code. However, functional programming has made big changes in how I write my (C++) code, making it simpler, s

              J Offline
              J Offline
              Josh Smith
              wrote on last edited by
              #46

              Stuart, you rock! Thanks a lot for sharing your thoughts. :cool:

              :josh: My WPF Blog[^] Without a strive for perfection I would be terribly bored.

              1 Reply Last reply
              0
              • J Josh Smith

                Stuart Dootson wrote:

                Your head's really going to flip when you get to binary functions:

                Sounds like fun! You seem to know quite a bit about functional programming, so let me ask you a question. From a business app developer's perspective, what are the benefits of using a functional language like Haskell in a real world app dev scenario? I know that there is a lot of fervor around multi-core/multi-processor computing, but what else is there? I'm just looking for more fuel to add onto my F# fire. Thanks. :)

                :josh: My WPF Blog[^] Without a strive for perfection I would be terribly bored.

                D Offline
                D Offline
                Dan Neely
                wrote on last edited by
                #47

                Josh Smith wrote:

                From a business app developer's perspective, what are the benefits of using a functional language like Haskell in a real world app dev scenario?

                a decade from now when your app is running on a 1024 core machine instead of an 8 core box it'll gracefully scale to use all the extra horsepower without requiring a rewrite. :cool:

                -- If you view money as inherently evil, I view it as my duty to assist in making you more virtuous.

                J 1 Reply Last reply
                0
                • D Dan Neely

                  Josh Smith wrote:

                  From a business app developer's perspective, what are the benefits of using a functional language like Haskell in a real world app dev scenario?

                  a decade from now when your app is running on a 1024 core machine instead of an 8 core box it'll gracefully scale to use all the extra horsepower without requiring a rewrite. :cool:

                  -- If you view money as inherently evil, I view it as my duty to assist in making you more virtuous.

                  J Offline
                  J Offline
                  Josh Smith
                  wrote on last edited by
                  #48

                  dan neely wrote:

                  a decade from now when your app is running on a 1024 core machine instead of an 8 core box it'll gracefully scale to use all the extra horsepower without requiring a rewrite.

                  That's awesome.

                  :josh: My WPF Blog[^] Without a strive for perfection I would be terribly bored.

                  S 1 Reply Last reply
                  0
                  • J Josh Smith

                    dan neely wrote:

                    a decade from now when your app is running on a 1024 core machine instead of an 8 core box it'll gracefully scale to use all the extra horsepower without requiring a rewrite.

                    That's awesome.

                    :josh: My WPF Blog[^] Without a strive for perfection I would be terribly bored.

                    S Offline
                    S Offline
                    Stuart Dootson
                    wrote on last edited by
                    #49

                    But unfortunately, not quite right. Unless you actually design your app to use more than one concurrent thread (and I don't necessarily mean kernel threads), it'll only ever be single-threaded and will only be able to use one core. You need to make liberal use of whatever concurrency paradigm is provided, in such a way that the runtime can perform balancing of threads across cores for you. So, in Erlang - use lots of processes! In .Net languages, use the threadpool liberally, I guess (I am certainly not a .Net expert - my usual language is C++). In Haskell, you'd want to use a reasonable number of threads via forkIO. Where FP does help you is that as data is (in general) immutable, shared data isn't updateable, so doesn't need to be locked - and also means you need to find some other way of communicating updates. Erlang probably has the nicest paradigm, with very lightweight processes (tens of thousands of processes are not a problem[^]), using message passing to communicate (but then, it was designed from ground up to be suitable for highly concurrent systems). Haskell has inter-thread channels, MVars and STM (software transactional memory).

                    J 1 Reply Last reply
                    0
                    • S Stuart Dootson

                      But unfortunately, not quite right. Unless you actually design your app to use more than one concurrent thread (and I don't necessarily mean kernel threads), it'll only ever be single-threaded and will only be able to use one core. You need to make liberal use of whatever concurrency paradigm is provided, in such a way that the runtime can perform balancing of threads across cores for you. So, in Erlang - use lots of processes! In .Net languages, use the threadpool liberally, I guess (I am certainly not a .Net expert - my usual language is C++). In Haskell, you'd want to use a reasonable number of threads via forkIO. Where FP does help you is that as data is (in general) immutable, shared data isn't updateable, so doesn't need to be locked - and also means you need to find some other way of communicating updates. Erlang probably has the nicest paradigm, with very lightweight processes (tens of thousands of processes are not a problem[^]), using message passing to communicate (but then, it was designed from ground up to be suitable for highly concurrent systems). Haskell has inter-thread channels, MVars and STM (software transactional memory).

                      J Offline
                      J Offline
                      Josh Smith
                      wrote on last edited by
                      #50

                      Stuart Dootson wrote:

                      Erlang probably has the nicest paradigm, with very lightweight processes (tens of thousands of processes are not a problem[^]),

                      :omg:

                      :josh: My WPF Blog[^] Without a strive for perfection I would be terribly bored.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups