r/programming • • May 08 '15

Five programming problems every Software Engineer should be able to solve in less than 1 hour

https://blog.svpino.com/2015/05/07/five-programming-problems-every-software-engineer-should-be-able-to-solve-in-less-than-1-hour
2.5k Upvotes

2.1k comments sorted by

View all comments

Show parent comments

2

u/Confusion May 08 '15

Haskell lists can only contain elements of a single type. You simply can't have a list with both 1 and 'a' in it.

2

u/mplsmesh May 08 '15

Ah. What about a compound type, which, based on the haskell wiki might look like this?

data intorstring = Int a | String b

If this is a thing, then your list would contain intorstring data types. (Edit: formatting)

2

u/Confusion May 08 '15

True, you could consider that a list of mixed types. You'd need some additional machinery to be able to use that list. Which suggests there is a better solution for the problem than mashing two types in a list :). My guess is they were aiming for things like

[1, 2, 3].zip(['a', 'b', 'c']).flatten

and that's not going to happen in Haskell. Which I think is a problem of the question, not of Haskell.

2

u/mplsmesh May 08 '15

I suspect that if you're contemplating compound types you've made some other trade-offs, so I wouldn't consider the extra machinery a knock against Haskell, but the price you're paying for whatever else you're getting. I can see what you might be getting at, however, if the question were meant to figure out if Haskell was the/a language you should use, but it'd only be useful if your whole program was about meshing together lists of heterogeneous types. Also, the author said you could use any language you like, so if that means cooking up some compound types in Haskell, I say go for it :)