[Haskell-cafe] Re: [Haskell] View patterns in GHC: Request for feedback

Stefan O'Rear stefanor at cox.net
Mon Jul 30 14:51:30 EDT 2007

On Mon, Jul 30, 2007 at 05:31:40AM -0400, Dan Licata wrote:
> With the functional dependency, you can't work with the view datatypes
> at all.  Once you write
> type Typ
> data TypView = Unit | Arrow Typ Typ
> instance View Typ TypView where
>   view = ...
> you're no longer allowed to take apart a TypView at all!

Exactly.  And I'm 100% convinced it's a non-issue, since all the
heavyweight view proposals don't allow you to manipulate view objects
*at all*.  My approach is no worse.

> E.g. you can't write
> outUnit :: TypView -> Bool
> outUnit Unit = True
> outUnit _    = False
> because the implicit application of the view function will mean that
> outUnit must consume a Typ.  

What would you use it for, anyway?  TypView objects don't exist
anywhere except internally in case-expressions.

> Personally, I'd rather have special syntax in the pattern (-> pat) than
> have these global effects on what you can do with certain types.

You can only declare the instance for TypView in the same module as
TypView itself, since otherwise it would conflict with the implicit
instance.  Therefore, providing an instance is no more "global" than
just renaming the type.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20070730/8b89edf2/attachment.bin

More information about the Haskell-Cafe mailing list