For the crust: Preheat the oven to 350F. Spread the grated coconut in a shallow pan or baking sheet. Place in the oven for 1020 minutes (fresh takes longer than packaged), stirring frequently, until lightly browned. Remove from the oven and let cool. Remove 1 1/2 cups of the toasted coconut for the filling.
Meanwhile, in a small saucepan melt the butter with the chocolate.
Combine the remaining 2 1/2 cups of toasted coconut with the melted butter chocolate mixture. Refrigerate for 15 minutes, stirring every 5 minutes, until the mixture begins to firm up. Pat the mixture into a 9 inch glass pie plate and chill again for at least 30 minutes before filling.
For the filling: Combine the sugar, cornstarch and salt in a medium saucepan and whisk until they are thoroughly mixed and powdery looking. Continue whisking while adding the milk, first by droplets, then in a steady stream. Whisk in the egg yolks until completely incorporated.
Place the saucepan over medium heat and cook the mixture, stirring constantly with a whisk or spoon, until it boils. Be sure to reach all over the bottom and sides of the pan with the whisk or spoon to prevent lumps from forming. When it reaches a full boil, reduce the heat to low and continue cooking and stirring for 3 minutes. Remove from the heat and beat in the butter, vanilla and 1 cup of the reserved toasted coconut.
Place a piece of plastic wrap directly on the surface of the pudding, covering it entirely to prevent a skin from forming on the surface. Let cool for 15 minutes. Remove the plastic, stir well and pour the mixture into the pie shell. Whip the cream (if using) just before serving and spread it over the pie. Sprinkle the remaining 1/2 cup of toasted coconut over the finished pie.