天道酬勤,学无止境

threepenny-gui

“Unable to load package `regex-posix` … unknown symbol ‘regerror’”

For a new project, I have been trying to build the threepenny-gui package, something which I have done many times in the past without any trouble. This time however, I ran into an unusual error message: > stack build threepenny-gui > configure threepenny-gui > Configuring threepenny-gui-0.9.0.0... threepenny-gui > build threepenny-gui > Preprocessing library for threepenny-gui-0.9.0.0.. threepenny-gui > Building library for threepenny-gui-0.9.0.0.. threepenny-gui > [ 1 of 29] Compiling Foreign.JavaScript.Include threepenny-gui > [ 2 of 29] Compiling Foreign.JavaScript.Resources threepenny-gui

2022-04-05 09:38:58    分类:问答    haskell   ghc   haskell-stack   threepenny-gui

具有多种 monad 类型的 Haskell do 子句(Haskell do clause with multiple monad types)

问题 我在 Haskell 中使用了一个名为 Threepenny-GUI 的图形库。 在这个库中,main 函数返回一个 UI monad 对象。 这让我很头疼,因为当我尝试将IO值解包到局部变量中时,我收到抱怨不同 monad 类型的错误。 这是我的问题的一个例子。 这是标准 main 函数的略微修改版本,如 Threepenny-GUI 的代码示例所示: main :: IO () main = startGUI defaultConfig setup setup :: Window -> UI () setup w = do labelsAndValues <- shuffle [1..10] shuffle :: [Int] -> IO [Int] shuffle [] = return [] shuffle xs = do randomPosition <- getStdRandom (randomR (0, length xs - 1)) let (left, (a:right)) = splitAt randomPosition xs fmap (a:) (shuffle (left ++ right)) 请注意第五行: labelsAndValues <- shuffle [1..10] 返回以下错误: Couldn't match type ‘IO’ with

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

Haskell do clause with multiple monad types

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 xs = do

2021-12-12 11:24:21    分类:问答    haskell   monads   threepenny-gui

三便士中基于行为的动态元素(Dynamic Elements based on Behaviour in threepenny-gui)

问题 简单来说,我正在寻找一种显示Behaviour (UI Element) 。 我的实际用例是显示一个可以过滤的表格。 所以我有一个函数tableElement :: String -> UI Element ( String参数是过滤条件)和一个输入字段filterElement :: Element ,它代表过滤器。 对我来说,将这些组合起来的最自然的方式是这样的: bFilter <- stepper "" (valueChange filterElement) displaySomehow (fmap tableElement bFilter) 这也是 Elm 的做法。 到目前为止,我发现的最接近的事情是使用sink children ,但这仅适用于[Element]而不适用于[UI Element] 。 此外,我必须使用一个虚拟元素作为父元素或摆弄其余的孩子。 用threepenny-gui实现这样的东西的最佳方法是什么? 回答1 (作者在这里) 请注意, UI Element表示一个操作,该操作在执行时可能会创建一个新的Element 。 您必须执行操作才能执行后者。 不幸的是,目前没有办法在 FRP 样式中完全做到这一点,每当过滤器发生变化时,您将不得不求助于onChanges组合器来重新创建表。 在那里,您可以使用set children 。 例子:

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

尝试在具有特殊行为的 Threepenny-gui 中渲染字段(Trying to render fields in threepenny-gui with special behaviour)

问题 我想要做的是设置字段,当它们处于焦点时显示详细信息,但当它们不在时显示摘要。 例如。 一种)。 当它失去焦点(变得模糊?)时,我将值保存在(状态?)地图中,然后将该值更改为旧值的函数(即汇总值) b)。 当它获得焦点时 - 我用我在地图中保存的旧值替换汇总值 我无法弄清楚如何做到这一点,但我想我可能需要一个状态 monad 和 UI monad。 我的尝试是: renderField :: Map->Int->UI (Element, Map) renderField vs ix = do input <- UI.input on UI.blur input $ \_ -> void $ do fieldValue <- get value input let newVs = insert ix fieldValue vs return input # set UI.value (calcNewValue fieldValue) on UI.focus input $ \_ -> void $ do let savedValue = findWithDefault "" ix vs return input # set UI.value savedValue return (input, newVs) 但我不能让这张地图工作 - 因为它需要跟踪所有的电话

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

Trying to render fields in threepenny-gui with special behaviour

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 fieldValue <-

2021-09-03 21:12:52    分类:问答    haskell   user-interface   threepenny-gui

在客户端/服务器编程中使用threepenny-gui/reactive(using threepenny-gui/reactive in client/server programming)

问题 我试图弄清楚如何使用 Haskell Threepenny-gui 及其反应性功能来编写一个程序,让 用户从列表框中选择一个项目将选择发送到外部服务器从服务器获取结果列表用结果填充列表框重复 看来我需要使用Handler 、 newEvent和register来完成上述操作。 如果有人能指点我一些现有的代码来做类似上面的事情,那就太好了。 我发现最接近的是GameThing.hs -gui samples目录中的 GameThing.hs (但它不使用register )。 更新: 我在问我是否应该使用Handler 、 newEvent和register --- 如果是的话,对这些函数进行一些说明或示例。 另外,要清楚的是,大局是: browser --> threepenny-gui (on localhost) --> backend server (anywhere on network) <-- <-- 换句话说,我需要做一些 IO(基于用户选择)然后显示该 IO 的结果。 更新:这是我的解决方案(基于@Taldykin 的回应):https://github.com/haroldcarr/rdf-triple-browser/tree/master/haskell/src 回答1 这是一段代码。 稍后我会添加说明。 {-# LANGUAGE LambdaCase

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

混合 Threepenny-Gui 和 StateT(Mixing Threepenny-Gui and StateT)

问题 我有一个关于 Threepenny-Gui 与 StateT 交互的问题。 考虑这个玩具程序,每次单击按钮时,都会在列表中添加一个“Hi”项: 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 "Click me!" myList <- UI.ul on UI.click myButton $ \_ -> element myList #+ [UI.li # set text "Hi"]

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

Haskell UI do clause, how to print?

This is a follow up question to this. I'm using a graphic library in Haskell called Threepenny-GUI. In this library the main function returns a UI monad object. I'm trying to execute a simple print command with no success. What is a right work around to enable printing for debugging purposes. Code: main :: IO () main = startGUI defaultConfig setup setup :: Window -> UI () setup w = do print "debug message 1 " Error: Couldn't match type ‘IO’ with ‘UI’ Expected type: UI () Actual type: IO () In a stmt of a 'do' block: print "labels and values "

2021-08-12 10:08:27    分类:问答    haskell   monads   threepenny-gui

Mixing Threepenny-Gui and StateT

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 "Click me!"

2021-06-27 06:27:02    分类:问答    haskell   monad-transformers   state-monad   threepenny-gui