- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
High Order Programming and Map Function
Sun, 2011-11-27, 19:15
Hello,
I am learning Scheme/Racket in uni. I try to apply, what I learn, with
Scala. I am learning high-order programming recently. In Scheme you
can use map function on multiple lists, if lists have same length:
(map + list1 list2 list3 list4 list5 list6)
You can assume that list1...list6 are integer lists like (list 1 2
3).
It is possible in scala until 3 lists:
(List(1, 1, 1), List(1, 1, 1), List(1, 1, 1)).zipped.map(_+_+_)
But this gives an error:
(List(1, 1, 1), List(1, 1, 1), List(1, 1, 1), List(1, 1,
1)).zipped.map(_+_+_+_)
Why it is not possible? Secondly is there sum function which takes n
arguments (Scheme + is takes n arguments). I don't want to write like _
+_+_... that.
I try to use Scala in pure functional way because Haskell and Scheme
does not have big library and they are not fast enough.
Sun, 2011-11-27, 20:07
#2
Re: High Order Programming and Map Function
In addition to the previous answer: the principal difference is that Scala is typed, and Scheme is not; so in Scheme you can basically write whatever you like, runtime will sort it out. You can add apples to oranges in Scheme.
Thanks,
-Vlad
2011/11/27 Mücahit Şenol <mucahitsenol86@gmail.com>
Thanks,
-Vlad
2011/11/27 Mücahit Şenol <mucahitsenol86@gmail.com>
Hello,
I am learning Scheme/Racket in uni. I try to apply, what I learn, with
Scala. I am learning high-order programming recently. In Scheme you
can use map function on multiple lists, if lists have same length:
(map + list1 list2 list3 list4 list5 list6)
You can assume that list1...list6 are integer lists like (list 1 2
3).
It is possible in scala until 3 lists:
(List(1, 1, 1), List(1, 1, 1), List(1, 1, 1)).zipped.map(_+_+_)
But this gives an error:
(List(1, 1, 1), List(1, 1, 1), List(1, 1, 1), List(1, 1,
1)).zipped.map(_+_+_+_)
Why it is not possible? Secondly is there sum function which takes n
arguments (Scheme + is takes n arguments). I don't want to write like _
+_+_... that.
I try to use Scala in pure functional way because Haskell and Scheme
does not have big library and they are not fast enough.
Sun, 2011-11-27, 20:17
#3
Re: High Order Programming and Map Function
2011/11/27 Vlad Patryshev :
> In addition to the previous answer: the principal difference is that Scala
> is typed, and Scheme is not; so in Scheme you can basically write whatever
> you like, runtime will sort it out. You can add apples to oranges in Scheme.
>
More precisely: Scala is statically typed, Scheme is dynamically typed.
Scheme lets you write more program but with less correction warranty.
For the author of the initial mail:
If you want to have more experience with static typing, closer to your
background,
before diving into Scala, you can play a bit with Typed Racket.
http://docs.racket-lang.org/ts-guide/
Best,
Nicolas.
2011/11/27 Mücahit Şenol <mucahitsenol86@gmail.com>
That's because the method 'zipped' is only pimped on Tuple2 and Tuple3. Try this:
List(List(1, 1, 1), List(1, 1, 1), List(1, 1, 1), List(1, 1, 1)).transpose.map(_.sum)