@@ -169,19 +169,21 @@ diff localizer context leftType rightType =
169169 go = diff localizer
170170 in
171171 case (leftType, rightType) of
172− (Type.Lambda _ _, Type.Lambda _ _) ->
173− let
174− leftParts = Type.collectLambdas leftType
175− rightParts = Type.collectLambdas rightType
176− in
172+ (Type.Aliased leftName leftArgs _, Type.Aliased rightName rightArgs _) | leftName == rightName ->
173+ docAppHelp localizer context leftName
174+ <$> sequenceA (zipWith (go App) (map snd leftArgs) (map snd rightArgs))
177175
178− if length leftParts /= length rightParts then
179− difference
180− (docLambda context (map (docType localizer Func) leftParts))
181− (docLambda context (map (docType localizer Func) rightParts))
176+ (Type.Aliased _ args real, _) ->
177+ go context (Type.dealias args real) rightType
182178
183− else
184− docLambda context <$> sequenceA (zipWith (go Func) leftParts rightParts)
179+ (_, Type.Aliased _ args real) ->
180+ go context leftType (Type.dealias args real)
181+
182+ (Type.Lambda _ _, _) ->
183+ diffLambda localizer context leftType rightType
184+
185+ (_, Type.Lambda _ _) ->
186+ diffLambda localizer context leftType rightType
185187
186188 (Type.Var x, Type.Var y) | x == y ->
187189 pure (text x)
@@ -216,16 +218,6 @@ diff localizer context leftType rightType =
216218 in
217219 diffRecord localizer leftFields leftExt rightFields rightExt
218220
219− (Type.Aliased leftName leftArgs _, Type.Aliased rightName rightArgs _) | leftName == rightName ->
220− docAppHelp localizer context leftName
221− <$> sequenceA (zipWith (go App) (map snd leftArgs) (map snd rightArgs))
222−
223− (Type.Aliased _ args real, _) ->
224− go context (Type.dealias args real) rightType
225−
226− (_, Type.Aliased _ args real) ->
227− go context leftType (Type.dealias args real)
228−
229221 (_, _) ->
230222 difference
231223 (docType localizer context leftType)
@@ -238,6 +230,37 @@ difference leftDoc rightDoc =
238230
239231
240232
233+-- FUNCTION DIFFS
234+
235+
236+diffLambda :: Localizer -> Context -> Type.Canonical -> Type.Canonical -> Diff Doc
237+diffLambda localizer context leftType rightType =
238+ let
239+ leftArgs = reverse $ Type.collectLambdas leftType
240+ rightArgs = reverse $ Type.collectLambdas rightType
241+
242+ extraToDoc types =
243+ map (dullyellow . docType localizer Func) types
244+
245+ extraLefts = reverse $ extraToDoc $ drop (length rightArgs) leftArgs
246+ extraRights = reverse $ extraToDoc $ drop (length leftArgs) rightArgs
247+
248+ alignedArgDiff =
249+ reverse <$> sequenceA (zipWith (diff localizer Func) leftArgs rightArgs)
250+ in
251+ docLambda context <$>
252+ case (extraLefts, extraRights, alignedArgDiff) of
253+ ([], [], _) ->
254+ alignedArgDiff
255+
256+ (_, _, Same docs) ->
257+ Diff (extraLefts ++ docs) (extraRights ++ docs)
258+
259+ (_, _, Diff lefts rights) ->
260+ Diff (extraLefts ++ lefts) (extraRights ++ rights)
261+
262+
263+
241264-- RECORD DIFFS
242265
243266