3

Why does this work...

Just.(+3) $ 6.7
Just $ truncate 8.9

...but not this?

Just.truncate $ 8.9

I tried resolving truncate to a simple Double -> Int:

let f :: Double -> Int; f = (\ x -> truncate x);

...but that doesn't appear to be the problem...

Just.f $ 5.6

<interactive>:41:1:
Failed to load interface for `Just'
Use -v to see a list of the files searched for.

Many thanks!

4

2 に答える 2

10

関数を構成するつもりならf . gf.g. もう少し読みやすく、このような問題を回避できます。

Foo.barフォームまたはFoo.BarHaskellの何かがある場合、それは修飾名として解析されます。Just.fそれが機能しない理由です:Justはモジュールではないため、 の「インターフェース」をJustロードできません。

Just.(+3)意図したとおりに機能する理由:(+3)は識別子ではなく正しいセクションであるため、ドットを修飾名の一部にすることはできません。それを解釈する唯一の方法は、それ.が演算子の中置適用であると仮定することです。(.)Just . (+3)

于 2014-02-15T20:07:19.687 に答える