Assignment 1, Task 1, 'non-trivial'

Moderator: Konzepte der Programmiersprachen

HerrmannIV
Neuling
Neuling
Beiträge: 7
Registriert: 18. Jun 2013 14:41

Assignment 1, Task 1, 'non-trivial'

Beitrag von HerrmannIV » 22. Nov 2018 09:56

Hi,
I wanted to ask why head::tail is trivial, wheras init and last are non-trivial.
Looking at the Scala Documentation, https://www.scala-lang.org/api/2.12.x/s ... /List.html I don't really see a difference in their triviality.
Thanks in advance.

0b101101101
Endlosschleifenbastler
Endlosschleifenbastler
Beiträge: 179
Registriert: 15. Apr 2015 18:24

Re: Assignment 1, Task 1, 'non-trivial'

Beitrag von 0b101101101 » 22. Nov 2018 12:19

Hey, I think head/tail should be mostly equivalent to head :: tail (although not always as nice).
For example init/last or ++ are probably more than trivial.

0b101101101
Endlosschleifenbastler
Endlosschleifenbastler
Beiträge: 179
Registriert: 15. Apr 2015 18:24

Re: Assignment 1, Task 1, 'non-trivial'

Beitrag von 0b101101101 » 22. Nov 2018 22:26

Wait, sorry. That was not an answer. :)

So the difference is, that a List(1, 2, 3, 4, 5) actually looks like (1, (2, (3, (4, (5, ()))))), so it is just one step to get the head and one step to get tail, but many steps to get last and many steps to get init (all-but-last).

Antworten

Zurück zu „Konzepte der Programmiersprachen“