Comments (6)
iiuc, like the technique that supports variadic functions, this technique lets a method have implementations with different arities.
(But this might be wrong, since I'm not quite sure what you mean, without a concrete program, and because I'm not familiar with the Op typeclass either)
from fltkhs.
@sboosali To me that sounds to be too little gain... Different arities can be done by uncurrying
from fltkhs.
Yes, which requires records. However, a design goal of this package is making the many fltk examples (written in C), fltk being extensively documented, as copy-pasteable and "mutually intelligible" as possible.
from fltkhs.
It can be done but it's ugly and it should really be part of the API but here's how to do it. Say you originally had something like :
ui :: IO ()
ui = do
window <- windowNew ...
begin window
button <- buttonNew ...
...
end window
...
If you only cared about Window
and not any of it's subclasses (like SingleWindow
, DoubleWindow
etc.) you can do:
within :: Ref Window -> IO () -> IO ()
within window action = do
begin window
action
end window
ui :: IO ()
ui = do
window <- windowNew ...
within window $ do
button <- buttonNew ...
...
...
However if you want it to work for any Window
it becomes ugly:
withinGeneric ::
(
Parent win Window,
Match x ~ FindOp win win (Begin ()),
Op (Begin ()) x win (IO ()),
Match y ~ FindOp win win (End ()),
Op (End ()) y win (IO ())
)
=> Ref win -> IO () -> IO ()
withinGeneric ref' action = do
() <- begin ref'
action
end ref'
ui :: IO ()
ui = do
window <- windowNew ...
withinGeneric window $ do
button <- buttonNew ...
...
...
There's a lot of complexity here but in essence the Parent win Window
constraint ensures that win
is a "subclass" of Window
, then the pair of Match x ~ FindOp win win (Begin ()), Op (Begin ()) x win (IO ())
first finds a function called begin
on win
and then ensure that it's of type IO ()
and then similarly with end
.
In any case this should be provided so feel free to leave this issue open and I'll add it to the API on the next release. You're also free to put up a PR if you want. :)
Edit: You'll also want to add:
{-# LANGUAGE FlexibleContexts, TypeFamilies #-}
from fltkhs.
And to answer your original question about FunDeps, I did try them originally but they didn't work because impl
is a function signature like (a -> b -> IO ())
. So for example, when setting the font size of a Widget, impl
is (Font -> IO ())
which has to be a constraint which is ignored for the purposes of FunDeps.
from fltkhs.
this is exactly what I do (and it work)
it is incredibly ugly though. I agree that it should be added into the library.
I will work on the PR :)
from fltkhs.
Related Issues (20)
- Return function pointer from `openCallback` so it can be freed. HOT 1
- Crash in FL.eventKey on special key HOT 8
- GL causes c2hs error on Mac due to missing type HOT 4
- after using setIcon on window it doesn't display application HOT 4
- Adding a Scrolled via FLUID generates wrong "scrollNew" call instead of "scrolledNew" HOT 1
- How to enable modern OpenGL? HOT 11
- unable to run basic example under nix HOT 1
- Fltkhs as stack dependency linking error on Windows 10 HOT 1
- install gotchas
- Build error in Setup.hs HOT 2
- Error building bundled fltkhs in custom Setup.hs HOT 1
- fltkhs-fluidtohs generates incorrect module names for nested modules
- addAndGetMenuItem is suprisingly slow HOT 8
- How to call findClicked?
- GHC 8.10.3 linking issue HOT 1
- Syntax error while installing with bundled fltkhs HOT 1
- Build fails with autoconf 2.70 and up HOT 8
- New branch's build artifacts stored in /tmp get erased
- Updating for base-4.14 (ghc 8.10) HOT 2
- cabal-install 3.4.0.0 breaks installation HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fltkhs.