문제

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!

도움이 되었습니까?

해결책

When you mean to compose functions, it's better to write f . g than f.g. It's a little more readable, and you avoid a bunch of problems like this one.

When you have something of the form Foo.bar or Foo.Bar in Haskell, it is parsed as a qualified name. That's why Just.f doesn't work: Just isn't a module, so the 'interface' for Just can't be loaded.

Why Just.(+3) does work as intended: (+3) is a right section, not an identifier, so the dot can't be part of a qualified name. The only way to interpret it is to assume that . is an infix application of the operator (.), so it must be Just . (+3).

다른 팁

A dot between a capitalized identifier and another identifier is parsed as a qualified name (eg. Data.Map.insert), so the error is telling you that it couldn't find a module named Just. You can simply add spaces around the dot to fix this.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top