haskell

Order of evaluation for multiple operators in infix form

大憨熊 提交于 2020-01-06 04:02:38
问题 Given this: data Base = Base { key1 :: Text, key2 :: Text, key3 :: Text } deriving (Show) instance FromJSON Base where parseJSON (Object v) = Base <$> ((v .: "base123") >>= (.: "key1")) <*> -- 1 ((v .: "base123") >>= (.: "key2")) <*> -- 2 ((v .: "base123") >>= (.: "key3")) -- 3 parseJSON _ = mzero What's the order of in which the infix operators <$> , <*> and <*> are applied? In other words, if I rewrite it in prefix form: instance FromJSON Base where parseJSON (Object v) = Base <$> ((<*>) (

why mingw32 and tdm-gcc64 behave differently using external gcc

大憨熊 提交于 2020-01-06 03:38:30
问题 I am trying to cabal install a component of wxHaskell (Haskell platform 2013.2 against wxWidgets 3.0). I was able to compile the git version with 32 bit mingw from mingw.org. But in the end, the installed wx cannot function correct, and running a minimal example gives runtime exceptions in wxc.dll. So I try to compile the same thing under TDM-GCC 4.8.1 64bit, since the wxWidgets people provide their binary in the form of TDM-GCC compiled binaries. But I immediately run into compilation errors

How to plug this type hole 2

百般思念 提交于 2020-01-06 03:29:07
问题 Following along from here (I've refactored the code from main into its own function) I am trying to get the following code to compile: import qualified Data.Text as T import Text.PDF.Info title :: FilePath -> String title path = do result <- pdfInfo path case result of Left someError -> do return "no title" Right info -> do case (pdfInfoTitle info) of Nothing -> return "no title" Just title -> return (T.unpack title) I am getting • Couldn't match type ‘[Char]’ with ‘Char’ Expected type: [Char

Parsec3 blocked by parsec, what ever I do

烂漫一生 提交于 2020-01-06 03:16:26
问题 using a cabal file looking like this (the relevant library part): build-depends: base >=4.8 && < 4.9, filepath >=1.4 && <1.5, time >=1.5 && <1.6, bytestring >=0.10 && <0.11, unix >=2.7 && <2.8, cryptohash >=0.11 && <0.12, process >=1.2 && <1.3, transformers >= 0.4 && < 0.5, text >= 1.2 && <= 1.3, base16-bytestring >= 0.1.1 && < 1.1.2, utf8-string >= 1 && < 1.1, directory >=1.2 && <1.3, regex-base >= 0.9 && < 1.0, regex-pcre >= 0.94 && < 0.95, regex-base >= 0.93 && < 0.94, direct-sqlite >=2.3

Drawing text on GTK's DrawingArea in Haskell

被刻印的时光 ゝ 提交于 2020-01-06 02:41:15
问题 I have a DrawingArea onto which I can draw using primitives such as drawRectangle and drawLine . How do I draw text onto that area? I'm most interested in something that quickly outputs a single line of text. Graphics.UI.Gtk.Gdk.Drawable.layoutLine seems to be what I want, but it wants a Graphics.Rendering.Pango.Layout.LayoutLine as input. How do I construct that LayoutLine ? Are there better alternatives than doing it this way? Thanks! 回答1: I don't know if you would consider using Cairo. If

How can I get a value after running a conduit?

一笑奈何 提交于 2020-01-06 02:21:10
问题 I need to do a little back and forth between with client and get either the Client object or their name string before starting up more pipelines. But I can't seem to get appSink to let me have a return value. How should I do this? checkAddClient :: Server -> ClientName -> AppData -> IO (Maybe Client) checkAddClient server@Server{..} name app = atomically $ do clientmap <- readTVar clients if Map.member name clientmap then return Nothing else do client <- newClient name app writeTVar clients $

what does “Not a PersistText value” mean?

半城伤御伤魂 提交于 2020-01-06 02:11:11
问题 I'm new to yesod and I'm trying to make the same blog project from this screencast: https://www.youtube.com/watch?v=SadfV-qbVg8 with the only difference being that I'm using MariaDB instead of PostgreSQL. Every time I add a new blog post and redirect to the page that shows it I see this error: [Error#yesod-core] get BlogPostKey {unBlogPostKey = SqlBackendKey {unSqlBackendKey = 5}}: field article: Not a PersistText value @(yesod-core-1.4.12:Yesod.Core.Class.Yesod ./Yesod/Core/Class/Yesod.hs

what does “Not a PersistText value” mean?

折月煮酒 提交于 2020-01-06 02:10:23
问题 I'm new to yesod and I'm trying to make the same blog project from this screencast: https://www.youtube.com/watch?v=SadfV-qbVg8 with the only difference being that I'm using MariaDB instead of PostgreSQL. Every time I add a new blog post and redirect to the page that shows it I see this error: [Error#yesod-core] get BlogPostKey {unBlogPostKey = SqlBackendKey {unSqlBackendKey = 5}}: field article: Not a PersistText value @(yesod-core-1.4.12:Yesod.Core.Class.Yesod ./Yesod/Core/Class/Yesod.hs

Reading user mouseclick position in haskells gloss

自闭症网瘾萝莉.ら 提交于 2020-01-06 02:01:36
问题 Edit: So i followed your pointers and got to this point: (following the rules of play) https://hackage.haskell.org/package/gloss-1.9.4.1/docs/Graphics-Gloss-Interface-Pure-Game.html drawBoard :: IO () drawBoard = play (InWindow "Tic Tac Toe" (300,300)(10,10)) yellow 10 board (testBoard) (handleKeys) (iteration) testBoard :: Board -> Picture testBoard board = grid where grid = color black (line [ (-100, -300), (-100, 300) ]) iteration :: Float -> Board -> Board iteration _ board = board

Extracting nested monadic result: m (m a) -> m a

百般思念 提交于 2020-01-06 01:45:20
问题 I have a function parseArgs :: [String] -> StdGen -> IO () which selects the function to run. The main looks like main = parseArgs <$> getArgs <*> getStdGen >>= id The problem I have, parseArgs <$> getArgs <*> getStdGen is of type IO (IO ()) , which I extract using (>>= id) which is of type Monad m => m (m b) -> m b . Is there a way to avoid requiring the "extraction" of the value while having just a single line function? 回答1: The easiest way would be with join : main = join $ parseArgs <$>