derektmueller / purescript-p5

p5.js bindings for PureScript
MIT License
19 stars 4 forks source link

'easier-to-use interfaces for functions with numeric suffixes' #5

Open m-bock opened 5 years ago

m-bock commented 5 years ago

As noted in the TODO section on the Readme:

Would this be the pattern?

-- | [p5js.org documentation](https://p5js.org/reference/#/p5/loadFont)
loadFont4 :: P5 -> String -> Maybe (Effect Unit) -> Maybe (Effect Unit) -> Font
loadFont4 p5 path callback onError = runFn4 loadFontImpl p5 path callback onError

-- | [p5js.org documentation](https://p5js.org/reference/#/p5/loadFont)
loadFont3 :: P5 -> String -> Maybe (Effect Unit) -> Font
loadFont3 p5 path callback = runFn4 loadFontImpl p5 path callback Nothing

-- | [p5js.org documentation](https://p5js.org/reference/#/p5/loadFont)
loadFont2 :: P5 -> String -> Font
loadFont2 p5 path = runFn4 loadFontImpl p5 path Nothing Nothing

Another way would be to omit the necessary first arg 'P5` in the counting :/

derektmueller commented 5 years ago

The README is actually about having a more intuitive way of translating the function overloading in the p5.js API. For example, the p5.js "vertex" function (https://p5js.org/reference/#/p5/vertex) has two function signatures:

vertex(x, y)
vertex(x, y, z, [u], [v])

In purescript-p5, these are implemented as "vertex" and "vertex2", respectively (see https://pursuit.purescript.org/packages/purescript-p5/0.10.0/docs/P5.Shape). Some p5.js functions like "background" have 6 signatures (https://p5js.org/reference/#/p5/background). This makes it hard to determine which function in purescript-p5 to use.