Re: Struggling with flatten function.

"Douglas Lewit [email protected] [ocaml_beginners]" <[email protected]> Fri, 30 Sep 2016 09:30:32 -0500
Newsgroups gmane.comp.lang.ocaml.beginners
Message-ID <CAM0XMJTg84=3pj5Wnp7yF5=EkpoDhb=w_a5_4cH97QvPtnzPZA@mail.gmail.com>
Thanks for the backup Manfred.  You're exactly right.  I think it's
important to mimic library functions as that really accelerates learning
any new language.  Yes, I "reinvented the wheel" but it's important to be
able to do that.  I remember taking a course in real analysis at IIT a few
years back.  The professor began with, "Would you guys be able to invent
Calculus if there weren't any Calculus textbooks in the world?"  We were
all reinventing the wheel!  But that's important because otherwise you end
up using stuff and have no idea how it works or where it came from or who
even developed it in the first place.

I think Ocaml is a fun language, and at the very least has helped me become
much better at recursion.  You can avoid recursion in a language like
Python or Ruby ( although you really shouldn't ) but in a functional
language you just can't avoid recursion.  The <head, tail> concept in Ocaml
has really helped me write some fun programs in Python and Ruby, programs
that I definitely could not have written before I began to study Ocaml.
Reminds me of what my high school Spanish teacher told me once.  She said,
"Doug, if you want to really get better at English and improve your reading
comprehension and writing skills, then study a foreign language!"  I think
this is also extremely true of computer programming languages.



On Thu, Sep 29, 2016 at 11:29 PM, Manfred Lotz [email protected]
[ocaml_beginners] <[email protected]> wrote:

>
>
> On Thu, 29 Sep 2016 23:38:59 +0200
> "Oliver Bandel [email protected] [ocaml_beginners]"
> <[email protected]> wrote:
>
> > Hello,
> >
> >
> > Zitat von "Douglas Lewit [email protected] [ocaml_beginners]"
> > <[email protected]> (Thu, 29 Sep 2016 15:10:56 -0500)
> >
> > > So I figured out the following:
> > >
> > > let rec flatten = function
> > > |[ ] -> [ ]
> > > |head :: tail -> head @ flatten tail ;;
> > >
> > > This mimics the builtin List.flatten function from the List
> > > module.
> > [...]
> >
> > So, you reinvented the wheel.
> >
>
> Perhaps, he simply wants to learn. As a learning experience it is a
> good thing to mimick library functions.
>
> --
> Manfred
> 
>