undecidable-instances

Why does this code using UndecidableInstances compile, then generate a runtime infinite loop?

一笑奈何 提交于 2019-12-03 10:45:25
问题 When writing some code using UndecidableInstances earlier, I ran into something that I found very odd. I managed to unintentionally create some code that typechecks when I believed it should not: {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE UndecidableInstances #-} data Foo = Foo class ConvertFoo a b where convertFoo :: a -> b instance (ConvertFoo a Foo, ConvertFoo Foo b) => ConvertFoo a b where convertFoo =

Why does this code using UndecidableInstances compile, then generate a runtime infinite loop?

时光怂恿深爱的人放手 提交于 2019-12-03 01:15:47
When writing some code using UndecidableInstances earlier, I ran into something that I found very odd. I managed to unintentionally create some code that typechecks when I believed it should not: {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE UndecidableInstances #-} data Foo = Foo class ConvertFoo a b where convertFoo :: a -> b instance (ConvertFoo a Foo, ConvertFoo Foo b) => ConvertFoo a b where convertFoo = convertFoo . (convertFoo :: a -> Foo) evil :: Int -> String evil = convertFoo Specifically, the convertFoo

How can undecidable instances actually hang the compiler?

旧街凉风 提交于 2019-12-01 18:34:04
By the time I first read serious criticism on -XUndecidableInstances , I had already completely accustomed to it, seeing it as merely removal of an annoying restriction Haskell98 has to make compilers easier to implement . In fact I've encountered plenty of applications where undecidable instances were needed, but none where they actually caused any problems related to undecidability. Luke's example is problematic for quite a different reason class Group g where (%) :: g -> g -> g ... instance Num g => Group g where ... – well, this would clearly be overlapped by any proper Group instance, so

How can undecidable instances actually hang the compiler?

自古美人都是妖i 提交于 2019-12-01 18:08:02
问题 By the time I first read serious criticism on -XUndecidableInstances, I had already completely accustomed to it, seeing it as merely removal of an annoying restriction Haskell98 has to make compilers easier to implement . In fact I've encountered plenty of applications where undecidable instances were needed, but none where they actually caused any problems related to undecidability. Luke's example is problematic for quite a different reason class Group g where (%) :: g -> g -> g ... instance