4 ms·
But the cool thing is that in many (most?) cases you can actually infer the type of reading from a string. You are going to do something with that value right?
by ent 13y ago
But the cool thing is that in many (most?) cases you can actually infer the type of reading from a string. You are going to do something with that value right? So you can say
1 + (read "1")
and the compiler will know that you must want to read "1" as a number and does that!
- deleted 13y ago[deleted]
- platz 13y agoThat kind inference only works because + is defined to work on Nums only (importing only prelude). You don't even need the initial 1. A nice trick but these are rather small details.
- dllthomas 13y agoYeah, I most commonly hit "oh, I need to annotate that" when I'm building some expression piece by piece in ghci, and so effectively what I'm doing with that value is "print it, as appropriate to the type" - which doesn't tell us much about what type it is.