天道酬勤,学无止境

threepenny-gui

Haskell do clause with multiple monad types

Question I'm using a graphic library in Haskell called Threepenny-GUI. In this library the main function returns a UI monad object. This causes me much headache as when I attempt to unpack IO values into local variables I receive errors complaining of different monad types. Here's an example of my problem. This is a slightly modified version of the standard main function, as given by Threepenny-GUI's code example: main :: IO () main = startGUI defaultConfig setup setup :: Window -> UI () setup w = do labelsAndValues <- shuffle [1..10] shuffle :: [Int] -> IO [Int] shuffle [] = return [] shuffle

2021-12-21 09:53:32    分类:技术分享    haskell   monads   threepenny-gui

Dynamic Elements based on Behaviour in threepenny-gui

Question To put it simple, I am looking for a way to display a Behaviour (UI Element). My actual use-case is displaying a table, which can be filtered. So I have a function tableElement :: String -> UI Element (the String parameter being the filter condition) and an input field filterElement :: Element, which represents the filter. The most natural way for me to combine these would be something like this: bFilter <- stepper "" (valueChange filterElement) displaySomehow (fmap tableElement bFilter) This is also the way it is done in Elm. The closest thing I have found so far is using sink

2021-09-18 14:25:38    分类:技术分享    haskell   frp   threepenny-gui

Trying to render fields in threepenny-gui with special behaviour

Question What I want to do is set up fields which show detail when they're in focus, but summary when they're not. eg. a). when it loses focus (gets blur?), I save the value in a (State?) Map and then change the value to a function of the old value (ie. the summary value) b). when it gets focus - I replace the summary value with the old value that I saved in the Map I cant' figure out how to do this, but I think I probably need a state monad and the UI monad. My try is: renderField :: Map->Int->UI (Element, Map) renderField vs ix = do input <- UI.input on UI.blur input $ \_ -> void $ do

2021-09-13 05:58:18    分类:技术分享    haskell   user-interface   threepenny-gui

using threepenny-gui/reactive in client/server programming

Question I am trying to figure out how to use Haskell threepenny-gui with its reactive functionality to write a program that lets the user select an item from a listBox send the selection to an external server get back a list of results from the server populate the listBox with the results repeat It seems I will need to use Handler, newEvent and register to do the above. If someone could point me to some existing code that does something like the above that would be great. The closest I have found is GameThing.hs in the threepenny-gui samples directory (but it doesn't use register). UPDATE: I

2021-09-01 04:00:46    分类:技术分享    haskell   threepenny-gui

Mixing Threepenny-Gui and StateT

Question I have a question on the interaction of Threepenny-Gui with StateT. Consider this toy program that, every time the button is clicked, adds a "Hi" item in the list: import Control.Monad import Control.Monad.State import qualified Graphics.UI.Threepenny as UI import Graphics.UI.Threepenny.Core hiding (get) main :: IO () main = startGUI defaultConfig setup setup :: Window -> UI () setup w = void $ do return w # set title "Ciao" buttonAndList <- mkButtonAndList getBody w #+ map element buttonAndList mkButtonAndList :: UI [Element] mkButtonAndList = do myButton <- UI.button # set text

2021-08-31 06:53:26    分类:技术分享    haskell   monad-transformers   state-monad   threepenny-gui