Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Haskell
Wiki community
Recent changes
Random page
HaskellWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Tangible Value
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Transmission-specific interfaces == While some interfaces can be implemented for different means of transmission, others are more specialized. === GUIs === Here are inputs for our shopping example above that specifically work with [[Phooey]]'s UI applicative functor. <haskell> applesU, bananasU :: Input UI Int applesU = iTitle "apples" (islider 3 (0,10)) bananasU = iTitle "bananas" (islider 7 (0,10)) shoppingUO :: Output UI (Int -> Int -> Int) shoppingUO = oTitle "shopping list" $ oLambda applesU (oLambda bananasU total) </haskell> We can then make curried and uncurried TVs: <blockquote> {| class="wikitable" ! code !! runUI rendering |- | style="padding:20px;" align=right| <hask>tv shoppingUO (+)</hask> | style="padding:20px;" align="center" | [[Image:shoppingU.png]] |- | style="padding:20px;" align=right | <hask>uncurryA $$ tv shoppingUO (+)</hask> | style="padding:20px;" align="center" | [[Image:shoppingPrU.png]] |} </blockquote> '''Note''': We could define other type classes, besides <hask>CommonInsOuts</hask>. For instance, <hask>islider</hask> could be made a method of a <hask>GuiArrow</hask> class, allowing it to be rendered in different ways with different GUI toolkits or even using HTML and Javascript. === IO === We can use <hask>IO</hask> operations in TV interfaces. The corresponding sink is <hask>OI</hask>, defined in [[TypeCompose]]. TV provides a few functions in its [http://hackage.haskell.org/package/TV/latest/doc/html/Interface-TV-IO.html <hask>IO</hask> module], including a close counterpart to the standard <hask>interact</hask> function. <haskell> interactOut :: Output IO OI (String -> String) interactOut = oLambda contentsIn stringOut </haskell> Assuming we have a file <tt>"test.txt"</tt> containing some lines of text, we can use it to test string transformations. <haskell> testO :: Output IO OI (String -> String) testO = oLambda (fileIn "test.txt") defaultOut </haskell> First, let's define higher-order functions that apply another function to the lines or on the words of a string. <haskell> onLines, onWords :: ([String] -> [String]) -> (String -> String) onLines f = unlines . f . lines onWords f = unwords . f . words </haskell> Next, specializations that operate on ''each'' line or word: <haskell> perLine,perWord :: (String -> String) -> (String -> String) perLine f = onLines (map f) perWord f = onWords (map f) </haskell> Some examples: <blockquote> {| class="wikitable" ! string function <hask>f</hask> !! <hask>runIO (tv test0 f)</hask> |- | style="padding:20px;" align=right| <hask>id</hask> | style="padding:20px;" align="center" | To see a World in a Grain of Sand And a Heaven in a Wild Flower, Hold Infinity in the palm of your hand And Eternity in an hour. - William Blake |- | style="padding:20px;" align=right| <hask>reverse</hask> | style="padding:20px;" align="center" | ekalB mailliW - .ruoh na ni ytinretE dnA dnah ruoy fo mlap eht ni ytinifnI dloH ,rewolF dliW a ni nevaeH a dnA dnaS fo niarG a ni dlroW a ees oT |- | style="padding:20px;" align=right| <hask>onLines reverse</hask> | style="padding:20px;" align="center" | - William Blake And Eternity in an hour. Hold Infinity in the palm of your hand And a Heaven in a Wild Flower, To see a World in a Grain of Sand |- | style="padding:20px;" align=right| <hask>perLine reverse</hask> | style="padding:20px;" align="center" | dnaS fo niarG a ni dlroW a ees oT ,rewolF dliW a ni nevaeH a dnA dnah ruoy fo mlap eht ni ytinifnI dloH .ruoh na ni ytinretE dnA ekalB mailliW - |- | style="padding:20px;" align=right| <hask>perLine (perWord reverse)</hask> | style="padding:20px;" align="center" | oT ees a dlroW ni a niarG fo dnaS dnA a nevaeH ni a dliW ,rewolF dloH ytinifnI ni eht mlap fo ruoy dnah dnA ytinretE ni na .ruoh - mailliW ekalB |} </blockquote> There are more examples [http://code.haskell.org/~conal/code/TV/src/Examples.hs in the TV repository] and in the [http://code.haskell.org/~conal/code/GuiTV/src/Examples.hs in the GuiTV repository]. See also "[http://journal.conal.net/#%5B%5Bseparating%20IO%20from%20logic%20--%20example%5D%5D separating IO from logic -- example]".
Summary:
Please note that all contributions to HaskellWiki are considered to be released under simple permissive license (see
HaskellWiki:Copyrights
for details). If you don't want your writing to be edited mercilessly and redistributed at will, then don't submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
DO NOT SUBMIT COPYRIGHTED WORK WITHOUT PERMISSION!
Cancel
Editing help
(opens in new window)
Toggle limited content width