[Haskell-cafe] Manual type-checking in graphs: Avoidable?

Jeffrey Brown jeffbrown.the at gmail.com
Fri Feb 19 05:28:24 UTC 2016


I had not!

I'm not seeing how such a solution would work. The nodes in a graph all
have to have the same type. If the phantom parameter distinguished two
nodes, they could not be used together.

But maybe you see something there that I don't?

On Thu, Feb 18, 2016 at 8:36 PM, Francesco Ariis <fa-ml at ariis.it> wrote:

> 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
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>



-- 
Jeffrey Benjamin Brown
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160218/81bd70d7/attachment.html>


More information about the Haskell-Cafe mailing list