The argument is not what I expect ( extensible record )

Interesting question.

One problem here is that when function funcOnSTree is used, it must be possible to replace the type parameter a with a single concrete type.

During different invocations type parameter can refer to different concrete types, so both of these work:

funcOnBase { foo = -5, bar = "" }
funcOnBase { foo = -5, baz = 3.7 }

But during a single invocation type parameter can’t refer to different concrete types.

Now if I change your function to this to fix this problem:

funcOnSTree : (Base a -> Bool) -> (Base b -> Bool) -> SubTree -> Bool
funcOnSTree fncA fncB x =
  case x of
    S1 s1 -> fncA s1
    S2 s2 -> fncB s2

I still get same error. So I don’t understand what’s really going on here?

Also this does work which shows that both Sub1 and Sub2 are accepted as Base a:

funcOnSTree : SubTree -> Bool
funcOnSTree x =
  case x of
    S1 s1 -> funcOnBase s1
    S2 s2 -> funcOnBase s2

I don’t understand why funcOnBase works while fncA/fncB doesn’t?

1 Like