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/mplsmesh May 08 '15

Can you expand on this? My first thought would be to use matching, like in ML, but I don't know any haskell so I could be wrong (though a quick search seems to imply matching is functionality haskell has).

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.

→ More replies (1)