# ASSERT failed! compiler/GHC/Core/RoughMap.hs:356 mfsolve package

Minimised to one file but could be minimised further. It's something to do with the synonym `type Phase n = n`

.

Failure found here: head.hackage!283 (closed)

```
{-# LANGUAGE DeriveGeneric, PatternGuards, PatternSynonyms,
MultiParamTypeClasses, FlexibleContexts, DeriveDataTypeable,
GeneralizedNewtypeDeriving #-}
{-
-}
module Math.MFSolve (addTrigTerms)
where
data Expr v n = Expr (LinExpr v n) [TrigTerm v n]
-- | A linear expression of several variables.
-- For example: @2*a + 3*b + 2@ would be represented as
-- @LinExpr 2 [(a, 2), (b, 3)]@.
data LinExpr v n = LinExpr n [(v, n)]
type Period v n = [(v, n)]
type Phase n = n
type TrigTerm v n = ([(v, n)], [(Phase n, LinExpr v n)])
data HM k a
-- | An angular function of the form @c + n*sin(theta + alpha)@
-- where @theta@, and @n@ are linear terms, @alpha@ and @c@ are constants.
type LinearMap v n = HM v (LinExpr v n)
type TrigEq v n = (Period v n, LinExpr v n, Phase n, n)
type TrigEq2 v n = HM (Period v n)
(HM v (Expr v n))
pattern LConst c = LinExpr c
addLin :: (Ord v, Num n, Eq n) => LinExpr v n -> LinExpr v n -> LinExpr v n
addLin (LinExpr c1 terms1) (LinExpr c2 terms2) = undefined
addExpr :: (Ord n, Ord v, Floating n) => Expr v n -> Expr v n -> Expr v n
addExpr (Expr lt1 trig1) (Expr lt2 trig2) =
Expr (addLin lt1 lt2) trig3
where
trig3 = merge trig1 trig2 addTrigTerms
-- merge two association lists, by combining equal keys with
-- the given function, and keeping keys sorted.
merge :: Ord k => [(k, v)] -> [(k, v)] -> (v -> v -> v) -> [(k, v)]
merge [] l _ = l
merge l [] _ = l
merge (a@(k,v):as) (b@(k2,v2):bs) f = case compare k k2 of
LT -> a: merge as (b:bs) f
EQ -> (k, f v v2): merge as bs f
GT -> b: merge (a:as) bs f
-- add trigonometric terms with the same period
addTrigTerms :: (Ord a, Ord t, Floating a)
=> [(a, LinExpr t a)] -> [(a, LinExpr t a)]
-> [(a, LinExpr t a)]
addTrigTerms [] p = p
addTrigTerms terms terms2 =
foldr mergeTerms terms terms2
where
mergeTerms (alpha, n) ((beta, m):rest) =
case addTrigTerm alpha n beta m of
Just (_, LConst 0) -> rest
Just (gamma, o) ->
mergeTerms (gamma, o) rest
Nothing ->
(beta, m) : mergeTerms (alpha, n) rest
mergeTerms a [] = [a]
```

```
<no location info>: error:
panic! (the 'impossible' happened)
GHC version 9.7.20230214:
ASSERT failed!
Phase
Call stack:
CallStack (from HasCallStack):
assertPpr, called at compiler/GHC/Core/RoughMap.hs:356:5 in ghc:GHC.Core.RoughMap
CallStack (from HasCallStack):
panic, called at compiler/GHC/Utils/Error.hs:454:29 in ghc:GHC.Utils.Error
Please report this as a GHC bug: https://www.haskell.org/ghc/reportabug
```