Skip to content

Instantly share code, notes, and snippets.

@jastice
Last active August 29, 2015 14:04
Show Gist options
  • Save jastice/2226ddab0226561cefc5 to your computer and use it in GitHub Desktop.
Save jastice/2226ddab0226561cefc5 to your computer and use it in GitHub Desktop.
The missing subtype problem
type Body s = { pos:(Int,Int), shape : s }
data Shape = Box {w:Int, h:Int} | Bubble {radius:Int}
mv: (Int,Int) -> Body a -> Body a
mv (x,y) body =
let (x0,y0)= body.pos
in { body | pos <- (x0+x, y0+y)}
myBubble = Body (0,0) <| Bubble {radius=10}
myBox = Body (10,10) <| Box {w=5, h=5}
bodies = [myBox,myBubble]
main = asText (map (mv (1,1)) bodies)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment