Subject + に + 形容詞/形容動詞


I understand that に can be used to mark the agent of an intransitive verb, but
I often see it being used with adjectives instead. For example, in the
sentence:

> 私にはできる  
>  As for me, I can do it.

に here marks the agent of the verb. The same thing can be said about 私にはわかる.
However, there are cases where に are followed by adjectives, which, although I
intuitively understand the meaning, do not understand the grammar behind them.

> 私には金が必要です。  
>  As for me, I need money.

> 寝るには早すぎる。  
>  It's too early to sleep.

> 電車に詳しいです。  
>  to know a lot about trains.

> 体にいいです。  
>  It's good for your body.

> 子供に怖い×  
>  Scary to children. (apparently incorrect.)

What is the function of に（は） here? In what situations can this be used?

Edit: I found a [related
question](https://japanese.stackexchange.com/questions/13693/using-%E3%81%AB-
with-adjectives), and this [linked
one](https://japanese.stackexchange.com/questions/4440/%E3%81%8C-and-%E3%81%AB-
interchangeability-and-difference-in-meaning), but the first one seems to have
conflicts about in which situations you can do this and the second question
only uses に to mark the agent of intransitive/potential verbs. [This
question](https://japanese.stackexchange.com/questions/72417/using-%E3%81%AB-%E3%81%AB%E3%81%A8%E3%81%A3%E3%81%A6-and-%E3%81%AB%E5%AF%BE%E3%81%97%E3%81%A6-with-
adjectives) also asks something very similar, but the answer doesn't really
address why 「子供に怖い」would be wrong.




Ok, I asked a native about this, and this is what I got from the conversation.
As @naruto says, I seem to have put a lot of different usages of に into the
same generalization.

> 体にいいです。  
>  It's good for your body.

> 子供に怖い×  
>  Scary to children.

These seem to be contractions of にとって. I couldn't find a reason for why 子供に怖い
sounds unnatural to most speakers, but this contraction seems to only work for
some adjectives. I was also told that 子供に怖い映画 sounds slightly more natural
because there is a noun attached to the end.

> 寝るには早すぎる。  
>  It's too early to sleep.

Verb+には seems to be a fixed pattern. IMABI seems to say this can be translated
to "In verb + ing". So a more literal translation would be "In sleeping, it is
too early."

> 私には金が必要です。  
>  As for me, I need money.

This is the purpose marker に. It shows who "needs money" and can only be used
with certain adjectives like 必要.

> 電車に詳しいです。  
>  to know a lot about trains.

This is the contraction of の場合には as described in [this
post](https://japanese.stackexchange.com/questions/72417/using-%E3%81%AB-%E3%81%AB%E3%81%A8%E3%81%A3%E3%81%A6-and-%E3%81%AB%E5%AF%BE%E3%81%97%E3%81%A6-with-
adjectives). So, "In the case of Trains, (I) know a lot about them". If I got
anything wrong, please correct me. I am not 100% sure that this is correct.
Also, if you are willing to give a more detailed (or accurate response),
please do.

