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. A little F# for you

A little F# for you

Scheduled Pinned Locked Moved The Lounge
csharpphpwpfcomregex
113 Posts 48 Posters 0 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 studying F# a lot recently and find it really mind-bending.  Tomas Petricek, a fellow CPian, let me sneak preview his series of F# articles and they are very good.  I took one of his examples and modified it a bit.  The following code displays "sum = 6", but how that happens is other-worldly...check it out:

    #light

    let rec sum nums =
      match nums with
      | head::tail -> head + sum(tail)
      | [] -> 0
     
    printf "sum = %i" (sum [1; 2; 3])

    Weird, eh?   F# is coooool. :cool:

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

    Steve EcholsS Offline
    Steve EcholsS Offline
    Steve Echols
    wrote on last edited by
    #4

    :omg: Whoa!


    - S 50 cups of coffee and you know it's on!

    • S
      50 cups of coffee and you know it's on!
      Code, follow, or get out of the way.
    J 1 Reply Last reply
    0
    • J Josh Smith

      I've been studying F# a lot recently and find it really mind-bending.  Tomas Petricek, a fellow CPian, let me sneak preview his series of F# articles and they are very good.  I took one of his examples and modified it a bit.  The following code displays "sum = 6", but how that happens is other-worldly...check it out:

      #light

      let rec sum nums =
        match nums with
        | head::tail -> head + sum(tail)
        | [] -> 0
       
      printf "sum = %i" (sum [1; 2; 3])

      Weird, eh?   F# is coooool. :cool:

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

      R Offline
      R Offline
      realJSOP
      wrote on last edited by
      #5

      Looks like a bastardization of dBase2 and interpreted basic.

      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
      -----
      "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

      J J 2 Replies Last reply
      0
      • R realJSOP

        Chris Maunder wrote:

        (Where's the sarcasm icon when I need it)

        I think you need more help with the site - it's become obvious that we can't rely on you to think of everything. :)

        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
        -----
        "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

        C Offline
        C Offline
        Chris Maunder
        wrote on last edited by
        #6

        As XP says: There are not sufficient resources to run that API.

        cheers, Chris Maunder

        CodeProject.com : C++ MVP

        1 Reply Last reply
        0
        • C Chris Maunder

          That looks like a huge advancement in clarity and code maintainability. (Where's the sarcasm icon when I need it)

          cheers, Chris Maunder

          CodeProject.com : C++ MVP

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

          Chris Maunder wrote:

          That looks like a huge advancement in clarity and code maintainability.

          Hahaha.  Yeah right.  I get the feeling that F# isn't going to become a "mainstream" .NET language anytime soon.  It's out there: far, far out there.  It has virtues different from clarity and code maintainability.  I'm just a newbie so don't quote me, but supposedly using F# as a functional programming language allows you to more easily write code which can be parallelized across multiple processors or cores.  I'm interested to see how to do that, because I think that's an important aspect of modern software design.

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

          M M M 3 Replies Last reply
          0
          • C Chris Maunder

            That looks like a huge advancement in clarity and code maintainability. (Where's the sarcasm icon when I need it)

            cheers, Chris Maunder

            CodeProject.com : C++ MVP

            S Offline
            S Offline
            soap brain
            wrote on last edited by
            #8

            I don't know....it seems a little too childish and easy. 001010101110101010010101110110111010100101101001010100101010110 111010010101110101011011011011100100100100101001001011010100101 011010100101001010001011010010110111101001010010000010101001010 101011110101111010100010111011111001000101010001010101001010101 There! That's much better. :cool: Uh....don't try and use that, by the way. ;P

            Mmmbop, ba duba dop Ba du bop, ba duba dop Ba du bop, ba duba dop Ba du, yeah Mmmbop, ba duba dop Ba du bop, Ba du dop Ba du bop, Ba du dop Ba du, yeah

            J 1 Reply Last reply
            0
            • J Josh Smith

              Chris Maunder wrote:

              That looks like a huge advancement in clarity and code maintainability.

              Hahaha.  Yeah right.  I get the feeling that F# isn't going to become a "mainstream" .NET language anytime soon.  It's out there: far, far out there.  It has virtues different from clarity and code maintainability.  I'm just a newbie so don't quote me, but supposedly using F# as a functional programming language allows you to more easily write code which can be parallelized across multiple processors or cores.  I'm interested to see how to do that, because I think that's an important aspect of modern software design.

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

              M Offline
              M Offline
              martin_hughes
              wrote on last edited by
              #9

              The daft thing is that they could have designed the syntax to be clear and maintainable, but instead went down the path of ghastly and even more ghastly.

              Me: Can you see the "up" arrow? User:Errr...ummm....no. Me: Can you see an arrow that points upwards? User: Oh yes, I see it now! -Excerpt from a support call taken by me, 08/31/2007

              G T 2 Replies Last reply
              0
              • Steve EcholsS Steve Echols

                :omg: Whoa!


                - S 50 cups of coffee and you know it's on!

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

                Steve Echols wrote:

                Whoa!

                My sentiments exactly!  The hardest part about learning F#, for me, is the fact that it has both new syntax and new concepts (well, new for me anyways).  I must say, though, that I haven't had this much geeky fun in a long time!  There's nothing better than freeing your mind a little bit, and thinking about things from a totally different perspective. :-D

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

                Steve EcholsS R R 3 Replies Last reply
                0
                • R realJSOP

                  Looks like a bastardization of dBase2 and interpreted basic.

                  "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                  -----
                  "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

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

                  John Simmons / outlaw programmer wrote:

                  Looks like a bastardization of dBase2 and interpreted basic.

                  Something tells me that you won't be an F# "early adopter." :)

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

                  R 1 Reply Last reply
                  0
                  • R realJSOP

                    Looks like a bastardization of dBase2 and interpreted basic.

                    "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                    -----
                    "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                    J Offline
                    J Offline
                    Jorgen Sigvardsson
                    wrote on last edited by
                    #12

                    Oh boy, looks sure can be deceiving...

                    J 1 Reply Last reply
                    0
                    • S soap brain

                      I don't know....it seems a little too childish and easy. 001010101110101010010101110110111010100101101001010100101010110 111010010101110101011011011011100100100100101001001011010100101 011010100101001010001011010010110111101001010010000010101001010 101011110101111010100010111011111001000101010001010101001010101 There! That's much better. :cool: Uh....don't try and use that, by the way. ;P

                      Mmmbop, ba duba dop Ba du bop, ba duba dop Ba du bop, ba duba dop Ba du, yeah Mmmbop, ba duba dop Ba du bop, Ba du dop Ba du bop, Ba du dop Ba du, yeah

                      J Offline
                      J Offline
                      Justin Perez
                      wrote on last edited by
                      #13

                      Ravel, you are one smart kid. I read your profile yesterday, and it baffels me how smart you are. You have a really bright future ahead of you. I really hope you didn't listen to Captin See Sharp yesterday. Don't do anything dumb!

                      I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")

                      S 1 Reply Last reply
                      0
                      • J Jorgen Sigvardsson

                        Oh boy, looks sure can be deceiving...

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

                        Joergen Sigvardsson wrote:

                        Oh boy, looks sure can be deceiving...

                        Well put.

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

                        1 Reply Last reply
                        0
                        • J Justin Perez

                          Ravel, you are one smart kid. I read your profile yesterday, and it baffels me how smart you are. You have a really bright future ahead of you. I really hope you didn't listen to Captin See Sharp yesterday. Don't do anything dumb!

                          I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")

                          S Offline
                          S Offline
                          soap brain
                          wrote on last edited by
                          #15

                          :-O:-O:-O:-O:-O:-O:-O:-O:-O:-O:-O:-O:-O:-O I'm not sure if it's possible to blush or be embarrassed to death, but I shall try! Uh, ahem! Anyway...pretending that was never uttered by me...:~ Umm....you've really...struck me dumb. I'm quite literally speechless. Not a word, a sentiment, an opinion, or even a sardonic quip. :cool: But no, I won't do anything like that. I promise. :rose:

                          Mmmbop, ba duba dop Ba du bop, ba duba dop Ba du bop, ba duba dop Ba du, yeah Mmmbop, ba duba dop Ba du bop, Ba du dop Ba du bop, Ba du dop Ba du, yeah

                          J 1 Reply Last reply
                          0
                          • J Josh Smith

                            I've been studying F# a lot recently and find it really mind-bending.  Tomas Petricek, a fellow CPian, let me sneak preview his series of F# articles and they are very good.  I took one of his examples and modified it a bit.  The following code displays "sum = 6", but how that happens is other-worldly...check it out:

                            #light

                            let rec sum nums =
                              match nums with
                              | head::tail -> head + sum(tail)
                              | [] -> 0
                             
                            printf "sum = %i" (sum [1; 2; 3])

                            Weird, eh?   F# is coooool. :cool:

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

                            L Offline
                            L Offline
                            leppie
                            wrote on last edited by
                            #16

                            Thats simply a map/reduce pattern, also called folding. Here is a Scheme example:

                            (define (fold func accum lst)
                            (if (null? lst)
                            accum
                            (fold func (func accum (car lst)) (cdr lst))))

                            (define (sum . lst) (fold + 0 lst))

                            (display "sum = ")
                            (display (sum 1 2 3)) ; prints 6 (0 + 1 + 2 + 3)
                            (newline)

                            (define (product . lst) (fold * 1 lst))
                            (display "product = ")
                            (display (product 1 2 3)) ; prints 6 (1 * 1 * 2 * 3)

                            xacc.ide
                            The rule of three: "The first time you notice something that might repeat, don't generalize it. The second time the situation occurs, develop in a similar fashion -- possibly even copy/paste -- but don't generalize yet. On the third time, look to generalize the approach."

                            J B S P 4 Replies Last reply
                            0
                            • J Josh Smith

                              I've been studying F# a lot recently and find it really mind-bending.  Tomas Petricek, a fellow CPian, let me sneak preview his series of F# articles and they are very good.  I took one of his examples and modified it a bit.  The following code displays "sum = 6", but how that happens is other-worldly...check it out:

                              #light

                              let rec sum nums =
                                match nums with
                                | head::tail -> head + sum(tail)
                                | [] -> 0
                               
                              printf "sum = %i" (sum [1; 2; 3])

                              Weird, eh?   F# is coooool. :cool:

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

                              D Offline
                              D Offline
                              Douglas Troy
                              wrote on last edited by
                              #17

                              You know your a nerd when ...

                              Josh Smith wrote:

                              Weird, eh? F# is coooool.


                              :..::. Douglas H. Troy ::..
                              Bad Astronomy |VCF|wxWidgets|WTL

                              J 1 Reply Last reply
                              0
                              • L leppie

                                Thats simply a map/reduce pattern, also called folding. Here is a Scheme example:

                                (define (fold func accum lst)
                                (if (null? lst)
                                accum
                                (fold func (func accum (car lst)) (cdr lst))))

                                (define (sum . lst) (fold + 0 lst))

                                (display "sum = ")
                                (display (sum 1 2 3)) ; prints 6 (0 + 1 + 2 + 3)
                                (newline)

                                (define (product . lst) (fold * 1 lst))
                                (display "product = ")
                                (display (product 1 2 3)) ; prints 6 (1 * 1 * 2 * 3)

                                xacc.ide
                                The rule of three: "The first time you notice something that might repeat, don't generalize it. The second time the situation occurs, develop in a similar fashion -- possibly even copy/paste -- but don't generalize yet. On the third time, look to generalize the approach."

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

                                leppie wrote:

                                Here is a Scheme example:

                                Wow, Scheme makes F# look "normal." :wtf:

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

                                L 1 Reply Last reply
                                0
                                • D Douglas Troy

                                  You know your a nerd when ...

                                  Josh Smith wrote:

                                  Weird, eh? F# is coooool.


                                  :..::. Douglas H. Troy ::..
                                  Bad Astronomy |VCF|wxWidgets|WTL

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

                                  Douglas Troy wrote:

                                  You know your a nerd when ...

                                  Takes one to know one. ;P

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

                                  D 1 Reply Last reply
                                  0
                                  • J Josh Smith

                                    I've been studying F# a lot recently and find it really mind-bending.  Tomas Petricek, a fellow CPian, let me sneak preview his series of F# articles and they are very good.  I took one of his examples and modified it a bit.  The following code displays "sum = 6", but how that happens is other-worldly...check it out:

                                    #light

                                    let rec sum nums =
                                      match nums with
                                      | head::tail -> head + sum(tail)
                                      | [] -> 0
                                     
                                    printf "sum = %i" (sum [1; 2; 3])

                                    Weird, eh?   F# is coooool. :cool:

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

                                    B Offline
                                    B Offline
                                    Brady Kelly
                                    wrote on last edited by
                                    #20

                                    I get it, but I couldn't do it. Match says if nums is null, return 0, otherwise return head + sum(tail). But: What does the "head::tail ->" mean?

                                    L J 2 Replies Last reply
                                    0
                                    • J Josh Smith

                                      leppie wrote:

                                      Here is a Scheme example:

                                      Wow, Scheme makes F# look "normal." :wtf:

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

                                      L Offline
                                      L Offline
                                      leppie
                                      wrote on last edited by
                                      #21

                                      But once you learn it :) Having a brace matching editor is rather essential for any function more than a few lines.

                                      xacc.ide
                                      The rule of three: "The first time you notice something that might repeat, don't generalize it. The second time the situation occurs, develop in a similar fashion -- possibly even copy/paste -- but don't generalize yet. On the third time, look to generalize the approach."

                                      1 Reply Last reply
                                      0
                                      • L leppie

                                        Thats simply a map/reduce pattern, also called folding. Here is a Scheme example:

                                        (define (fold func accum lst)
                                        (if (null? lst)
                                        accum
                                        (fold func (func accum (car lst)) (cdr lst))))

                                        (define (sum . lst) (fold + 0 lst))

                                        (display "sum = ")
                                        (display (sum 1 2 3)) ; prints 6 (0 + 1 + 2 + 3)
                                        (newline)

                                        (define (product . lst) (fold * 1 lst))
                                        (display "product = ")
                                        (display (product 1 2 3)) ; prints 6 (1 * 1 * 2 * 3)

                                        xacc.ide
                                        The rule of three: "The first time you notice something that might repeat, don't generalize it. The second time the situation occurs, develop in a similar fashion -- possibly even copy/paste -- but don't generalize yet. On the third time, look to generalize the approach."

                                        B Offline
                                        B Offline
                                        Brady Kelly
                                        wrote on last edited by
                                        #22

                                        Now that hurts! :~

                                        1 Reply Last reply
                                        0
                                        • B Brady Kelly

                                          I get it, but I couldn't do it. Match says if nums is null, return 0, otherwise return head + sum(tail). But: What does the "head::tail ->" mean?

                                          L Offline
                                          L Offline
                                          leppie
                                          wrote on last edited by
                                          #23

                                          Thats the pattern matcher I assume :)

                                          xacc.ide
                                          The rule of three: "The first time you notice something that might repeat, don't generalize it. The second time the situation occurs, develop in a similar fashion -- possibly even copy/paste -- but don't generalize yet. On the third time, look to generalize the approach."

                                          B 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