Re: Introduction to Functional Programming in OCaml at Paris Diderot (MOOC)
"Douglas Lewit [email protected] [ocaml_beginners]" <[email protected]> Wed, 17 Aug 2016 16:10:43 -0500
| Newsgroups | gmane.comp.lang.ocaml.beginners |
|---|---|
| Message-ID | <CAM0XMJRgyf7fABR3dyZ8k742TNLWppys=OW4P+G1KrASZN2Y1Q@mail.gmail.com> |
I'm replying here to an older message, but what the hell. Anyhow, the course looks great. I wish it started sooner than September 26th. By "Informatics" I'm assuming they mean "analysis of data" or the combination of statistics and computer programming. Or is there another definition for Informatics? I'm kind of proud of the following functions that I created while playing around with the language. I was wondering how I could reverse a list without resorting to the @ operator. Well I think I found a way to do it. So.... ( Copied from memory, so forgive typos, mistakes, etc. ) *exception Empty_List of string ;;* *(* Here I am borrowing the names of pre-defined functions in Haskell. *)* *let rec last = function * * |[ ] -> raise ( Empty_List "An empty list does not have a last element!" )* * |head :: tail -> if tail = [ ] then head else last tail ;;* *let rec init = function* * |[ ] -> raise ( Empty_List "The init function only applies to non-empty lists." )* * |head :: tail -> if tail <> [ ] then head :: init tail else [ ] ;;* *let rec reverse = function * * |[ ] -> [ ]* * |lst -> ( last lst ) :: reverse ( init lst ) ;;* *I'm pretty happy with these functions, especially since the cons operator or :: is supposed to be more efficient or faster than the append operator or @.* Of course I have to wonder why recursing over lists is better than iterating over arrays. In traditional imperative programming all these things are done through iteration and array manipulation. But in Ocaml and Haskell these things are done by recursing over lists or linked lists rather than arrays. ( Although I realize that Ocaml does offer the array data structure. I'm not really sure if Haskell has arrays. I don't know that much about Haskell. ) So then this begs the questions: 1) Why is recursion superior to iteration?, and 2) Why are lists better than arrays? I know I'm playing the Devil's Advocate here, but it might be good to reflect on why functional programming is the way to go rather than studying a more "traditional" language such as C or C++ or Java. I also recently read some blog post where the author said something like, "We need mutable data when modeling phenomena in the real world!" He was casting some doubt on the legitimacy of the practice of allowing only immutable data types in a programming language. He basically said that you have to assign, reassign and update variables in order to successfully model real world data. Is that really true? Any thoughts? I appreciate the feedback. Have a wonderful day. Regards, Douglas Lewit On Sat, Jul 9, 2016 at 4:47 AM, Manfred Lotz [email protected] [ocaml_beginners] <[email protected]> wrote: > > > Hi all, > I thought it is a good idea to call attention to a forthcoming OCaml > beginner's course, starting at Sep 26, 2016 as an online course at FUN > (https://www.fun-mooc.fr/). > > Introduction to Functional Programming in OCaml > Université Paris Diderot, Sep 26 2016 till Dec 12, 2016. > > https://www.fun-mooc.fr/courses/parisdiderot/56002S02/session02/about > > Important for those, who like me do not (unfortunately) speak > French, the course language is in English. > > I think it will at some point in time appear at the News section at > https://ocaml.org/. > > -- > Manfred > >