5 ms·
That seems odd. It seems that `arg |> func` would simply be sugar for `func arg` (or a function that accomplished this). Why are they not equivalent?
by thinkpad20 13y ago
That seems odd. It seems that `arg |> func` would simply be sugar for `func arg` (or a function that accomplished this). Why are they not equivalent?
- throwaway344 13y ago|> is a low priority operator, which forces evaluation to occur first on the left. [1; 2; 3] |> List.filter (fun a -> a < 3) |> List.sum is the same as List.sum (List.filter (fun a -> a < 3) [1; 2; 3]) arg |> func is the same as func (arg)
- thinkpad20 13y agoYeah, that's exactly what I thought. It doesn't explain (or I don't see it yet) why the first example he gave wouldn't compile, but the second would.
- latkin 13y agoF# type inference runs left -> right, top -> bottom. In the first snippet, the lambda is encountered first, and the compiler has no knowledge of what the type of "d" is, so it can't assume d has a ".Hour" member. In the second snippet, the compiler has already seen the input list and knows it contains DateTimes, so when it encounters the lambda, "d" is known to be a DateTime and everything is groovy.
- thinkpad20 13y agoAh, I see, thanks for that. So it's not running Hindley Milner (or at least, not unless it's quite heavily modified). That's not surprising, I guess, since it takes no small amount of effort to get HM to work in an OO/imperative setting.