[Haskell-cafe] Manual type-checking in graphs: Avoidable?
Francesco Ariis
fa-ml at ariis.it
Fri Feb 19 04:36:59 UTC 2016
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
More information about the Haskell-Cafe
mailing list