tag:blogger.com,1999:blog-5981432593633653194.post5727722465642155198..comments2020-08-08T13:07:51.211+01:00Comments on Sound and Software: Faking it with higher rank (Existential Quantification pt. 2)Anonymoushttp://www.blogger.com/profile/14086288462709102194noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-5981432593633653194.post-62972043890391902802012-06-12T15:29:15.732+01:002012-06-12T15:29:15.732+01:00Unfortunately, using a GADT in this manner is esse...Unfortunately, using a GADT in this manner is essentially the same as existential quantification (see http://blog.ezyang.com/2011/03/type-tech-tree/ for more details), and suffers from the same problem. Consider this simplified example:<br /><br />data GDT a where<br /> GDT :: (Show a, Num a) => a -> GDT a<br /><br />test2 gdt = case gdt of<br /> GDT n -> show $ 2*n<br /><br />compiled at -O2, this results in the core<br /><br />Foo.test2 :: forall a_a9R. Foo.GDT a_a9R -> GHC.Base.String<br />[GblId,<br /> Arity=1,<br /> Str=DmdType S,<br /> Unf=Unf{Src=, TopLvl=True, Arity=1, Value=True,<br /> ConLike=True, Cheap=True, Expandable=True,<br /> Guidance=IF_ARGS [20] 110 0}]<br />Foo.test2 =<br /> \ (@ a_af3) (gdt_aab :: Foo.GDT a_af3) -><br /> case gdt_aab of _ { Foo.GDT $dShow_af5 $dNum_af6 n_aac -><br /> GHC.Show.show<br /> @ a_af3<br /> $dShow_af5<br /> (GHC.Num.*<br /> @ a_af3<br /> $dNum_af6<br /> (GHC.Num.fromInteger @ a_af3 $dNum_af6 Foo.test3)<br /> n_aac)<br /> }<br /><br />so it's still going through the dictionary methods.<br /><br />This is actually the same core that's produced for "data EQu = forall a. (Show a, Num a) => EQu a", modulo naming.Anonymoushttps://www.blogger.com/profile/14086288462709102194noreply@blogger.comtag:blogger.com,1999:blog-5981432593633653194.post-78246359655524620802012-06-11T23:03:26.558+01:002012-06-11T23:03:26.558+01:00That inefficiency problem will not exist with a re...That inefficiency problem will not exist with a regular non-existentially quantified type, such as:<br />data Ebuffer a where Ebuffer :: (Buffer a) => EBuffer a<br />am I correct? Can this data type be used instead to accomplish the same task?Hussain Sobhyhttps://www.blogger.com/profile/14600246493528044733noreply@blogger.com