Skip to content

Instantly share code, notes, and snippets.

drawString :: DrawingArea -> RGB -> Coordinate -> String -> IO ()
drawString drawArea (r, g, b) (x, y) str = do
drawWin <- widgetGetDrawWindow drawArea
let gcVal = newGCValues {foreground = Color r g b}
gc <- gcNewWithValues drawWin gcVal
layout <- widgetCreateLayout drawArea str
layoutSetText layout str
layoutSetWrap layout WrapWholeWords
layoutSetWidth layout . Just $ 300
lineCount <- layoutGetLineCount layout
-- タイムラインのフィールドにデータを描画
drawTimelineData :: GUI -> [Tweet] -> IO ()
drawTimelineData gui tweets = do
let home = homeTimeline gui
field = timelineField home
tlText = foldl (\s -> \t -> s ++ (show t) ++ "\n") "" tweets
-- 描画イベントを発生させる
GUI.drawString field (0, 0, 0) (0, 0) tlText
return ()
drawString :: DrawingArea -> DrawWindow -> RGB -> Coordinate -> String -> IO ()
drawString drawArea drawWin (r, g, b) (x, y) str = do
let gcVal = newGCValues {foreground = Color r g b}
gc <- gcNewWithValues drawWin gcVal
layout <- widgetCreateLayout drawArea str
layoutSetText layout str
layoutSetWrap layout WrapWholeWords
layoutSetWidth layout . Just $ 300
lineCount <- layoutGetLineCount layout
widgetSetSizeRequest drawArea 300 1000
{-# LANGUAGE TemplateHaskell, QuasiQuotes #-}
module THUtility where
import Language.Haskell.TH
import Control.Monad
import Control.Applicative
mapT :: Int -> ExpQ -> ExpQ
mapT count f = do
vars <- replicateM count $ newName "x"
lamE [tupP $ map varP vars] (tupE $ map (appE f . varE) vars)
{-# LANGUAGE TemplateHaskell, QuasiQuotes #-}
import Language.Haskell.TH
import Control.Monad
mapT :: Int -> ExpQ -> ExpQ
mapT count f = do
vars <- replicateM count $ newName "x"
lamE [tupP $ map varP vars] (tupE $ map (appE f . varE) vars)
{-# LANGUAGE TemplateHaskell, QuasiQuotes #-}
import Language.Haskell.TH
import Control.Monad
import Control.Applicative
mapMT :: Int -> ExpQ -> ExpQ
mapMT count f = do
vars <- replicateM count $ newName "x"
let ops = '(<$>):repeat '(<*>)
lamE [tupP $ map varP vars] $ foldl (\x -> \(op, y) -> (appE (appE (varE op) x) (appE f (varE y)))) (conE $ tupleDataName count) (zip ops vars)
{-# LANGUAGE TemplateHaskell, QuasiQuotes, NoMonomorphismRestriction #-}
module THUtility where
import Language.Haskell.TH
import Control.Monad
import Data.IORef
import Graphics.UI.Gtk hiding (add)
import Graphics.Rendering.Cairo
import Graphics.UI.Gtk.Gdk.GC
import Graphics.UI.Gtk.Glade
import Control.Applicative
-- GUILibrary.hs
-- アイコン画像を取得
getIcon :: String -> IO String
getIcon url = do
let outFile = "./icon/" ++ urlEncode url
fileExist <- doesFileExist outFile
if fileExist
then return outFile
else do
let request = defaultGETRequest $ fromJust $ parseURI url
-- GUILibrary.hs
-- アイコン画像を取得
getIcon :: String -> IO String
getIcon url = do
let outFile = "./icon/" ++ urlEncode url
fileExist <- doesFileExist outFile
if fileExist
then return outFile
else do
let request = defaultGETRequest $ fromJust $ parseURI url
> (define $f (lambda [$x $pat] (match-all x (Multiset Integer) [pat m])))
f
> (define $pat1 <cons $m <cons ,m _>>)
pat1
> (define $pat2 <cons $m <cons ,(- m 1) _>>)
pat2
> (define $x {2 3 3 4 5})
x
> (test (f x pat1))
{3}