What is the difference between these two type declarations? The second one is wrong but I can't convince myself why it should be wrong. Is it because Int not a constraint class and it is only an instance of one? My curiousity is why #1 can't be written in the form of #2. I apologise if I am using wrong terminology as type, class and constraint class are used with not much distinction. To add context, this problem is to find a function that will find an element by passing in a list and an index argument.
elementAt''' ::[a]-> Int ->a -- #1
elementAt''' [] _= error "list is empty"
elementAt''' list index
| (index < 1) = error "index has to be positive number"
| otherwise= list !! (index-1)
elementAt'''' ::(Int b)=>[a]-> b ->a -- #2
elementAt'''' [] _= error "list is empty"
elementAt'''' list index
| (index < 1) = error "index has to be positive number"
| otherwise= list !! (index-1)
Thank you. I just began learning Haskell.
Yours sincerely,
Justin
I check my email at 9AM and 4PM everyday
If you have an EMERGENCY, contact me at +447938674419(UK) or +60125056192(Malaysia)