Skip to content

Instantly share code, notes, and snippets.

@evancz
Created November 11, 2014 04:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evancz/6df7c788ffa5e555fdd9 to your computer and use it in GitHub Desktop.
Save evancz/6df7c788ffa5e555fdd9 to your computer and use it in GitHub Desktop.
Trying out different ways to avoid toFloat conversions, based on this discussion (https://groups.google.com/forum/#!topic/elm-discuss/YPA2ww2P9PU)
import Window
import Color
floatify : (Int,Int) -> (Float,Float)
floatify (x,y) =
(toFloat x, toFloat y)
scene (w,h) =
flow down
[ container (floor w) (floor (h / 2)) middle (asText "blue")
|> color Color.blue
, container (floor w) (ceiling (h / 2)) middle (asText "red")
|> color Color.red
]
main = lift scene (lift floatify Window.dimensions)
import Window
import Color
scene (w,h) =
let halfHeight = h // 2
flow down
[ container w halfHeight middle (asText "blue")
|> color Color.blue
, container w (h - halfHeight) middle (asText "red")
|> color Color.red
]
main = lift scene Window.dimensions
import Window
import Color
scene (w,h) =
flow down
[ container w (floor (toFloat h / 2)) middle (asText "blue")
|> color Color.blue
, container w (ceiling (toFloat h / 2)) middle (asText "red")
|> color Color.red
]
main = lift scene Window.dimensions
import Window
import Color
scene (w,h) = flow down
[ container w (toFloat h/toFloat 2 |> floor) middle (asText "blue") |> color Color.blue
, container w (toFloat h/toFloat 2 |> ceiling) middle (asText "red") |> color Color.red
]
main = lift scene Window.dimensions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment