panic! the 'impossible' happend! - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

James King
{-# LANGUAGE DerivingVia #-}

module CodeGen where

import Control.Monad.Writer

newtype Name = Name String
  deriving (Eq, Show)

newtype CodeGen a = CodeGen (Writer [a] ())
  deriving Applicative via Writer [a]

This is just some code I'm toying around with but I haven't encountered the "impossible" before. Neat! Anyone know what's happening here? Is it simple improper use of DerivingVia or should there be a type error here?

Lysxia

This is certainly a weird instance.

Lysxia

Applicative on Writer [a] would give you pure :: x -> Writer [a] x
but for CodeGen you need pure :: x -> Writer [x] ()

Lysxia

CodeGen a is coercible to Writer [a] (), but that doesn't mean CodeGen is coercible to Writer [a], it doesn't really make sense since there is not a in CodeGen.

TheMatten

BTW, this should probably be filled as a bug on GHC repo - I don't think "impossible" can ever be considered to be a proper error