If you have a typical sloped shingle roof with attic, this does not seem like a very good plan.
Standard blue board & pink board foam runs about R-5 per inch, so it would take 10" of this stuff to get to your R-50.
This stuff is also expensive and highly flammable. Thermax makes a fire retardant, more costly foam that has a little better R value per inch at approx. R-7.5, but that would still take 7" of material to get to your R-50.
This going to be very expensive and impractical.
You would have to somehow sandwich the foam between two layers of decking so that you have something for the foam to sit atop, and something for the shingles to nail to.
Really, the only practical way to achieve the R-50 would be with blown in or multiple layers of roll fiberglass.
Depending upon your location, R-50 may be a little overkill too, something like R-30 may be plenty.