Cause of error
Actually, in this case the compiler expects Float , but gets Int . Int is the index argument to the placePiece function, and it expects Float because Basics.(/) Expects Float arguments.
Why literal numbers work
When you just print the codes, the compiler can understand that although you use integers, you can use them as a Float instead of Int .
Error fixing
There are three ways to fix this error. If you really want to accept Int, but want floating point division, you have to turn the integer into a floating point number:
import Graphics.Element exposing (..) columns = 2 main = placePiece 10 placePiece: Int -> Element placePiece index = show (toFloat index / columns)
If you agree with the placePiece function with a floating point number, you can change the signature like:
import Graphics.Element exposing (..) columns = 2 main = placePiece 10 placePiece: Float -> Element placePiece index = show (index/columns)
If you need integer division, you can use the Basics.(//) operator:
import Graphics.Element exposing (..) columns = 2 main = placePiece 10 placePiece: Int -> Element placePiece index = show (index
Apanatshka
source share