[Haskell-cafe] Re: Proposal: Sum type branches as extended types (as
Type!Constructor)
Gabriel Riba
griba2001 at gmail.com
Fri Jun 4 07:57:30 EDT 2010
Jason Dagit <dagit <at> codersbase.com> writes:
>
> How will this proposal scale with data types that have multiple
> alternatives that make sense? No natural examples come to mind
> so how about a contrived example:
>
> data List2 a = Nil | Cons a (List2 a) | Cons2 a a (List2 a)
>
> Now I want to define hd for both Cons and Cons2, but not Nil.
> Do I use an either type like this?
> hd :: Either (List2!Cons a) (List2!Cons2 a) -> a
>
> It seems like some other syntax would be desirable here, maybe:
> hd :: List2!{Cons, Cons2} a -> a
>
> How should it work for functions where no type signature is supplied?
> Shouldit infer the type we would now and only enable the
> subset of constructors when the type is explicit as above?
>
> Jason
I agree with your syntax proposal.
hd :: List2!{Cons, Cons2} a -> a
in functions where no type signature, type inference could work as usual.
After normal types passes typechecker with type inference,
then Constructor matching could be checked.
More information about the Haskell-Cafe
mailing list