Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basics docs TYPE MISMATCH: sqrt >> isEven >> not #1097

Open
geofflangenderfer opened this issue Jan 14, 2021 · 1 comment
Open

Basics docs TYPE MISMATCH: sqrt >> isEven >> not #1097

geofflangenderfer opened this issue Jan 14, 2021 · 1 comment

Comments

@geofflangenderfer
Copy link

geofflangenderfer commented Jan 14, 2021

This shows up in a comment and in the docs.

A compilable example would save beginners' time. For example:

> composed = cos >> sin
<function> : Float -> Float
> composed pi
-0.8414709848078965 : Float
> sin (cos pi)
-0.8414709848078965 : Float
> sin (cos pi) == composed pi
True : Bool

I believe it's an error:

>import Arithmetic
> sqrt
<function> : Float -> Float
> Arithmetic.isEven
<function> : Int -> Bool
> not
<function> : Bool -> Bool
> sqrt >> Arithmetic.isEven >> not
-- TYPE MISMATCH ---------------------------------------------------------- REPL

The right argument of (>>) is causing problems.

4|   sqrt >> Arithmetic.isEven >> not
             ^^^^^^^^^^^^^^^^^^^^^^^^
The right argument is:

    Int -> Bool

But (>>) needs the right argument to be:

    Float -> c

Hint: With operators like (>>) I always check the left side first. If it seems
fine, I assume it is correct and check the right side. So the problem may be in
how the left and right arguments interact!

Note: Read <https://elm-lang.org/0.19.1/implicit-casts> to learn why Elm does
not implicitly convert Ints to Floats. Use toFloat and round to do explicit
conversions.

Here's a correction:

> checkSqrtOdd x = sqrt x - (x |> sqrt |> floor |> toFloat) > 0.001
> checkSqrtOdd 15
True : Bool
> checkSqrtOdd 16
False : Bool
> checkSqrtOdd 17
True : Bool

@github-actions
Copy link

Thanks for reporting this! To set expectations:

  • Issues are reviewed in batches, so it can take some time to get a response.
  • Ask questions a community forum. You will get an answer quicker that way!
  • If you experience something similar, open a new issue. We like duplicates.

Finally, please be patient with the core team. They are trying their best with limited resources.

@geofflangenderfer geofflangenderfer changed the title sqrt >> isEven >> not Basics docs TYPE MISMATCH: sqrt >> isEven >> not Jan 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant