[Haskell-cafe] Do people use visitor pattern in Haskell...
nicholls.mark at vimn.com
Mon Jun 22 07:28:32 UTC 2015
Brilliant, v interesring
Excuse the spelling, sent from a phone with itty bitty keys, it like trying to sow a button on a shirt with a sausage.
On 19 Jun 2015, at 19:37, Phil Ruffwind <rf at rufflewind.com> wrote:
>> class Wibble a where
>> visit :: (Foo -> b) -> (Bar -> b) -> a -> b
> The type `forall b. (X -> b) -> (Y -> b) -> b` is isomorphic to
> `Either X Y`. If you rearrange the signature of `visit` a little bit,
> visit_ :: a -> forall b . (Foo -> b) -> (Bar -> b) -> b
> you can see that you're really just defining a function `a -> Either
> Foo Bar`. So the class can be simplified to:
> class Wibble' a where
> visit' :: a -> Either Foo Bar
> It follows that `WibblePackage'` is equivalent to
> type WibblePackage' = forall a . (WibbleInstance a, a)
> type WibbleInstance a = a -> Either Foo Bar
> Because of the `forall`, there's nothing you can do with the second
> component of the tuple (`a`) except to apply it to the first (`a ->
> Either Foo Bar`), so it's just a long-winded way of saying
> type WibblePackage'' = Either Foo Bar
> In a non-strict language like Haskell, there's no reason to use such a
> complicated type signature to delay the application of `a -> Either
> Foo Bar` to `a`.
This e-mail (and any attached files) is confidential and protected by copyright (and other intellectual property rights). If you are not the intended recipient please e-mail the sender and then delete the email and any attached files immediately. Any further use or dissemination is prohibited.
While MTV Networks Europe has taken steps to ensure that this email and any attachments are virus free, it is your responsibility to ensure that this message and any attachments are virus free and do not affect your systems / data.
Communicating by email is not 100% secure and carries risks such as delay, data corruption, non-delivery, wrongful interception and unauthorised amendment. If you communicate with us by e-mail, you acknowledge and assume these risks, and you agree to take appropriate measures to minimise these risks when e-mailing us.
MTV Networks International, MTV Networks UK & Ireland, Greenhouse, Nickelodeon Viacom Consumer Products, VBSi, Viacom Brand Solutions International, Be Viacom, Viacom International Media Networks and VIMN and Comedy Central are all trading names of MTV Networks Europe. MTV Networks Europe is a partnership between MTV Networks Europe Inc. and Viacom Networks Europe Inc. Address for service in Great Britain is 17-29 Hawley Crescent, London, NW1 8TT.
More information about the Haskell-Cafe