
19 Feb
2016
19 Feb
'16
4:36 a.m.
On Thu, Feb 18, 2016 at 06:50:26PM -0800, Jeffrey Brown wrote:
Suppose then you wanted to write a function that, given a person, returns the names of all their hamsters. To make sure the call makes sense, the function would have to first check that the input is in fact a person. Since persons and hamsters are both constructors of the same type, you can't let Haskell's robust, beautiful type-checking system distinguish them for you; you've got to write something like "case n of Person _ -> True; _ -> False".
Is there some way around writing such manual checks?
Hello Jeffrey, have you considered using Phantom types [1]? [1] https://wiki.haskell.org/Phantom_type#Simple_examples