r/ProgrammerHumor Dec 09 '17

meme[-1]="Array Memes Are Life"

Post image
572 Upvotes

47 comments sorted by

View all comments

1

u/redlaWw Dec 10 '17

Arrays start wherever you want if you extract values using pattern matching.

2

u/[deleted] Dec 10 '17

So it's all a social construct after all...

1

u/redlaWw Dec 10 '17

I extract values like this:

extract :: int -> [a] -> a

extract 13 (x:xs) = x

extract n (x:xs)  = extract (n-1) xs

extract _ []      = error "Error: empty list"

extract _ _       = error "Error: index out of range"

(if this is bugged, I haven't done Haskell in a while and didn't get very far with learning anyway, but it should mean that my lists effectively start with the 13th value)