
Hi, Am Dienstag, den 24.02.2015, 11:14 +0100 schrieb Henning Thielemann:
On Tue, 24 Feb 2015, Ivan Lazar Miljenovic wrote:
I've used fromJust in the past when I knew the value would be Just by construction.
If you know that the value is always Just by construction, why don't you express this with the types, i.e. by turning from 'Maybe a' to 'a'?
Not everything can be expressed with types. Example: You build a graph data structure around Data.Map. Your abstract interface makes sure that in your graph, you only reference nodes that are in the domain of the map. So it is reasonable to use "fromJust (M.lookup key map)"¹ internally. The Maybe is part of another packages interface, and rightly so – how would you get rid of it? (In this case, one could argue that you should write fromMaybe (error "I broke the graph")..." but it still refutes the argument that you can always replace "Maybe a" by "a" if you know that it is a Just anyways.) Greetings, Joachim ¹ Yes, this is also "map M.! key" – which, if we were consistent, needs to be deprecated as well. -- Joachim “nomeata” Breitner mail@joachim-breitner.de • http://www.joachim-breitner.de/ Jabber: nomeata@joachim-breitner.de • GPG-Key: 0xF0FBF51F Debian Developer: nomeata@debian.org