Thoughts Heap

A Blog by Roman Gonzalez.-

RSS
Aug
23rd
Tue
permalink

Haskell’s Tuple like structures in Clojure

As you may know by now, there is no equivalent for Haskell’s tuples in Clojure, in order to replicate this behavior, you will need to use vectors of two items. Clojure provides the functions first and second to get the elements out of the tuple vector

Tuples in Haskell are very useful when using the zip function, one way to replicate this behavior in Clojure is using the map function with the vector function and the lists you want to join as parameters.

This can be compared to Haskell code:

The cool thing about the map function in Clojure, is that given its polymorphic nature, it can do the same things that the zipWithN, mapM and map functions do in Haskell.

Pretty neat though confusing at the start.

  1. romanandreg posted this
blog comments powered by Disqus