Re: List.flatten....
"Douglas Lewit [email protected] [ocaml_beginners]" <[email protected]> Sat, 2 Apr 2016 09:07:53 -0500
| Newsgroups | gmane.comp.lang.ocaml.beginners |
|---|---|
| Message-ID | <CAM0XMJTfBx9VB5Av83vxA58PN4TomPrOuCb2jryZz4RK8Qyb6g@mail.gmail.com> |
Sure can.... 'a -> 'a list -> a' list is for List.cons 'a list -> 'a list -> a' list is for List.append I think those 2 functions start to overlap however if you're working with a list of lists. Well "overlap" could be a poor choice of words, but what if 'a refers to a list and 'a list -> refers to a list of lists, so then you would have something like: [1; 2; 3; 4] :: [[5; 6; 7; 8]] ;; The result is a list of lists or nested lists. A professor of mine is studying Haskell. I asked him if he liked it, to which he replied.... "It's very LISTY". And I think LISP is really an acronym for LISt Processing. It seems that this is a hallmark of most ( or all? ) functional programming languages. A big emphasis on lists and list manipulations. Of course how do you define a list? In some languages the words "array" and "list" are interchangeable. ( I think Python for example does have arrays, but in general in Python arrays and lists are interchangeable. ) I read somewhere that Ocaml lists have more in common with Java linked lists than Java arrays. Okay.... I'm rambling! I better shut up! I hope everyone on the list has a great weekend. Best, Douglas. On Sat, Apr 2, 2016 at 5:33 AM, 'Mr. Herr' [email protected] [ocaml_beginners] <[email protected]> wrote: > > > > > On 02.04.2016 07:32, Douglas Lewit [email protected] [ocaml_beginners] > wrote: > > > > I think I read somewhere that the cons operator :: is more efficient than > the append operator @, so whenever possible it's better to use cons rather > than append. > > # List.cons ;; (* this is :: *) > > - : 'a -> 'a list -> 'a list = <fun> > > # List.append ;; (* this is @ *) > > - : 'a list -> 'a list -> 'a list = <fun> > > # > > > there is a tiny little difference, can you find it? > > /Str. > > >