Recursive type usage problem

type rec student = {taughtBy: teacher}
and teacher = {students: array<student>}

let rec vicky = { taughtBy: teacher } 
and teacher = {students: [vicky]}

I’m getting error: This kind of expression is not allowed as right-hand side of `let rec’

1 Like

rec can be used with other expressions besides functions. The problem here is that it apparently cannot be used with arrays. I’m not sure why.

Using a list instead works:

type rec student = {taughtBy: teacher}
and teacher = {students: list<student>}

let rec vicky = {taughtBy: teacher}
and teacher = {students: list{vicky}}
6 Likes

Interesting, it worked only with function expressions when I tried in the past. Probably because of something similar to arrays here.

This might be a v10 regression.

cc/ @cristianoc

5 Likes