haskell

Template Haskell compile error when calling with different parameters

陌路散爱 提交于 2020-01-04 08:24:26
问题 Why does the following fail to compile (on GHC 7.4.2)? {-# LANGUAGE TemplateHaskell #-} f1 = $([| id |]) main = print $ (f1 (42 :: Int), f1 (42 :: Integer)) Note that the following compiles fine: {-# LANGUAGE TemplateHaskell #-} f1 = id -- Don't use template Haskell here. main = print $ (f1 (42 :: Int), f1 (42 :: Integer)) Is there a language extension I can use to make the former compile? I know the Template Haskell seems silly in this example, but it's a simplified version of a more complex

flycheck-haskell and doctest don't work on Cabal 3.0 v2-build project

為{幸葍}努か 提交于 2020-01-04 07:55:14
问题 I tried to create a Nix-style local build (v2-build) project on Cabal 3.0. But several development tools (flycheck-haskell and doctest) don't work. They worked on new-build project on Cabal 2.4. Error message says they cannot find dependencies, as far as I read. $ cabal v2-clean $ cabal v2-build $ cabal v2-test Build profile: -w ghc-8.8.1 -O1 In order, the following will be built (use -v for more details): - hstest9-0.1.0.0 (test:doctestd) (first run) Configuring test suite 'doctestd' for

Implement Gauss-Jordan elimination in Haskell

…衆ロ難τιáo~ 提交于 2020-01-04 07:54:32
问题 We want to program the gauss-elimination to calculate a basis (linear algebra) as exercise for ourselves. It is not homework. I thought first of [[Int]] as structure for our matrix. I thought then that we can sort the lists lexicographically. But then we must calculate with the matrix. And there is the problem. Can someone give us some hints. 回答1: Consider using matrices from the hmatrix package. Among its modules you can find both a fast implementation of a matrix and a lot of linear algebra

Where is the source for: “Function application has higher precedence than infix operators” [Haskell]

匆匆过客 提交于 2020-01-04 07:26:45
问题 I'm learning about operator precedence in Haskell. Several places across the web mention that function application has higher precedence than operators, but I couldn't find a definitive source for that. Here is one such mention from A Gentle Introduction To Haskell: Function application has higher precedence than any infix operator There is a section in the Haskell 98 Report that alludes to it: normal constructor application has higher precedence than infix constructor application Where is a

Keeping track of history in ghci

你说的曾经没有我的故事 提交于 2020-01-04 07:13:18
问题 How does history management work in GHCI or other Haskell-based REPLs? Since Haskell is a pure language, I guess it's implemented using a monad, perhaps the state monad. Kindly note I'm a beginner in Haskell, so please provide a detailed explanation rather than just linking to the source. 回答1: This is a simplified example of how a program might keep a history of commands entered by the user. It basically has the same structure as the number guessing game, so once you understand that you

Keeping track of history in ghci

半腔热情 提交于 2020-01-04 07:11:29
问题 How does history management work in GHCI or other Haskell-based REPLs? Since Haskell is a pure language, I guess it's implemented using a monad, perhaps the state monad. Kindly note I'm a beginner in Haskell, so please provide a detailed explanation rather than just linking to the source. 回答1: This is a simplified example of how a program might keep a history of commands entered by the user. It basically has the same structure as the number guessing game, so once you understand that you

hslogger & Duplicate Log Lines

混江龙づ霸主 提交于 2020-01-04 07:01:59
问题 I've configured logging like so: import System.Environment import System.Log.Logger import System.Log.Handler (setFormatter) import System.Log.Handler.Simple (streamHandler) import System.Log.Formatter import System.IO (getLine, stdout) main = do stdOutHandler <- streamHandler stdout DEBUG >>= \lh -> return $ setFormatter lh (simpleLogFormatter "[$time : $loggername : $prio] $msg") updateGlobalLogger "Linker" (setLevel DEBUG . setHandlers [stdOutHandler]) infoM "Linker" "Hello world!"

Using Aeson generics to construct JSON with a value as key holding another value

别等时光非礼了梦想. 提交于 2020-01-04 06:56:35
问题 Toying a bit with the github gist API while trying to get down with the Aeson JSON library. I've run into a problem with the generated ToJSON instance, and I don't know exactly how to solve it. I need to contain a value inside and the key that is associated to the value also needs to be a value and not a predefined key name. It's a bit easier to show. The desired output is, { "public": true, "description": "Something..", "files": {"This Thing.md": {"content": "Here we go!"}} } where the value

state monad haskell

痴心易碎 提交于 2020-01-04 06:50:24
问题 I want to write a function for calculating the average using the State Monad in haskell this is the code I wrote as far import Control.Monad.State type MyState = (Double,Double) media s (a,n)= ((a*n+s)/(n+1),n+1) getAverage:: Double ->State MyState s1-> Double getAverage s c=get >>= \s0 -> let (x,s1) =media s s0 in put s1 >> return x I got this error when compile in GHCI, and I stuck there can you help me to understand what is wrong, thank you in advance 回答1: The code you provided gives this

Haskell, Aeson: Parsing nested JSON with part unnecessary values

走远了吗. 提交于 2020-01-04 06:32:51
问题 I'm a beginner trying to learn more about Haskell and Aeson by parsing some json files I find online. I have a .json that looks like this "Abilities": { "Prime": { "Ammo": 210, "Available": true, "Diposition": 3, "Type": "Secondary", "Class": "Pistols", "NormalAttack": { "Chance": 0.25, "Streak": 2, "Rate": 2.67, "ShotType": "Hit-Scan", "Damage": { "Front": 15, "Back": 15, "Up": 120, "Down": 40 }, "Status": 0.25 } "Accuracy": 9.8, "Reload": 3, "Name": "Prime", "Magazine": 16, }, "Dual": {