[Haskell-cafe] Automatically infer Newtype instance
Dmitry Bogatov
KAction at gnu.org
Wed Apr 9 17:20:07 UTC 2014
> > I think, that Newtype instances are transitive, and there is only one
> > sane definiton is (pack . pack). But in example below I have to use
> > UndecidableInstances and they seems to loop somewhere
> > (Context reduction stack overflow; size = 132).
> >
> > To my understanding, Ghc tries to prove, that exists only one type b,
> > and somewhy fail at it(It is unclear, why), but is it any way to say to
> > it that I take responsibility, that ANY b would be nice?
> you should checkout genealizednewtype deriving :)
> https://ghc.haskell.org/trac/haskell-prime/wiki/NewtypeDeriving
>
> GHC has had it for quite some time
>
> also the Coerce Machinery in 7.8 GHC provides a stronger version of your
> NewType style class
No, it is not what I want. With it I would have to enumerate every type
down. so for A_n
newtype A0 = A0 Int
...
newtype A_n = A_n A_{n-1}
I would need list all n instances. In more general say, I want
following:
class Foo a b where
foo :: a -> b
--- Yes, UndecidableInstances. Yes, ambitious types.
--- Take any b, yes unsafe, trust me, it will be okay.
instance (Foo a b, Foo b c) => Foo a c where
foo = foo . foo
--
Best regards, Dmitry Bogatov <KAction at gnu.org>,
Free Software supporter, esperantisto and netiquette guardian.
git://kaction.name/rc-files.git
GPG: 54B7F00D
More information about the Haskell-Cafe
mailing list