tag:blogger.com,1999:blog-6655746112052720933.post4993383362531684674..comments2022-03-30T18:43:33.525-05:00Comments on Notes on Haskell: Proxies and Delegation vs. Existential TypesAdam Turoffhttp://www.blogger.com/profile/11941071792943377879noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-6655746112052720933.post-34277019921326364552007-06-20T13:12:00.000-05:002007-06-20T13:12:00.000-05:00To anonymous: That only works if you have an known...To anonymous: That only works if you have an known number of fixed types to begin with. Part of the advantage of using objects is that you can extend functionality at any time by just adding a new class. The URL class in java has a factory that can generate one of many types of URLs given the url string. Anyone can add a new url type (ie- blah:// in addition to http://, ftp:// etc.) and simply register it for use with the system. You need existential types in Haskell to do the same thing.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6655746112052720933.post-13312302014914383042007-02-01T10:39:00.000-05:002007-02-01T10:39:00.000-05:00I'm copying my comment from Reddit in case you don...I'm copying my comment from <a href="http://programming.reddit.com/info/12ago/comments">Reddit</a> in case you don't frequent that site:<br /><br />Maybe I'm missing something, but I would do that example as<br /><br />data Archive = ZipArchive ZipArchive<br /> | TarArchive TarArchive<br /> | TarGzArchive TarGzArchive<br /> | TarBz2Archive TarBz2Archive<br /><br />makeArchive :: String -> Archive<br />makeArchive fn<br /> | ".zip" `isSuffixOf` fn = ZipArchive (makeZipArchive fn)<br /> | ".tar" `isSuffixOf` fn = TarArchive (makeTarArchive fn)<br /> | ...Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6655746112052720933.post-63933553952138517672007-02-01T05:03:00.000-05:002007-02-01T05:03:00.000-05:00Your data declaration has only one constructor and...Your data declaration has only one constructor and it takes only one parameter. Therefore you can use a "newtype" declaration:<br /><br /><b><br />newtype ArchiveProxy = forall a. (Archive a) => ArchiveProxy a<br /></b><br /><br />The "newtype" creates a distinct type just like "data" but the compiler knows it is really an alias for "forall a. Archive a => a" and after type checking it deletes the type from the program.<br /><br />So the running program is guaranteed to have zero overhead from constructing/wrapping and destructing/unwrapping the Archive type.TuringTesthttps://www.blogger.com/profile/17742921018460479810noreply@blogger.com