2013-12-18 7 views
3

나는 FRP와 threepenny-gui로 시작하려하고 있으며 기본적인 것들까지도 할 수있는 방법이 없다. 가정하자행동에서 출발 한 요소 (기능적 반응 프로그래밍)

I 함수 너무

timesClicked :: Element -> Behavior Int 
timesClicked elem = accumulate (+) 0 (1 <$ UI.click elem) 

로 정의하고 난 페이지에 Behavoir 값을 표시 할.

나는

setup :: Window -> UI() 
setup rootWindow = void $ do 
    button <- UI.button #+ [ string "Clickity!" ] 
    output <- UI.p 
    getBody rootWindow #+ 
    map element [ button, output ] 

    let clicks = timesClicked loginButton 

편집과 같은 작업을 수행 할 수 있습니다 : 전체 코드 here 작업.

동작에 출력을 첨부하는 방법을 모르겠습니다.

답변

3

아하, 이제 알아 냈어. 다른 사람들에게도 이것을 남겨두고있다.

timesClicked elem = accumB (0::Int) ((+1) <$ UI.click elem) 


setup :: Window -> UI() 
setup rootWindow = void $ do 
    button <- UI.button #+ [ string "Clickity!" ] 
    output <- UI.p 
    getBody rootWindow #+ 
    map element [ button, output ] 

    clicks <- timesClicked button 
    -- sink :: ReadWriteAttr x i o -> Behavior i -> UI x -> UI x 
    element output # sink text (show <$> clicks) 

누군가 내 진행 상황을 따르고 싶다면 github에 입력했습니다.