haskell

Hiding versions of random from GHCi

人盡茶涼 提交于 2020-12-10 06:24:55
问题 I am working with the newsynth package and am running into a bug that I am starting to suspect has to do with the update random-1.2.0 over the summer ( newsynth was last updated in late 2019, and random-1.2.0 came out in June. I have run cabal update since then, which is why both seem to be installed.) Here is the code that I ran in GHCi: λ> import System.Random λ> import Quantum.Synthesis.Ring λ> import Quantum.Synthesis.Diophantine λ> g <- getStdGen λ> diophantine g (RootTwo 5 0)

Hiding versions of random from GHCi

我是研究僧i 提交于 2020-12-10 06:24:52
问题 I am working with the newsynth package and am running into a bug that I am starting to suspect has to do with the update random-1.2.0 over the summer ( newsynth was last updated in late 2019, and random-1.2.0 came out in June. I have run cabal update since then, which is why both seem to be installed.) Here is the code that I ran in GHCi: λ> import System.Random λ> import Quantum.Synthesis.Ring λ> import Quantum.Synthesis.Diophantine λ> g <- getStdGen λ> diophantine g (RootTwo 5 0)

Hiding versions of random from GHCi

我与影子孤独终老i 提交于 2020-12-10 06:24:24
问题 I am working with the newsynth package and am running into a bug that I am starting to suspect has to do with the update random-1.2.0 over the summer ( newsynth was last updated in late 2019, and random-1.2.0 came out in June. I have run cabal update since then, which is why both seem to be installed.) Here is the code that I ran in GHCi: λ> import System.Random λ> import Quantum.Synthesis.Ring λ> import Quantum.Synthesis.Diophantine λ> g <- getStdGen λ> diophantine g (RootTwo 5 0)

How does mapM work with const functions in Haskell?

怎甘沉沦 提交于 2020-12-08 07:52:48
问题 as I had been looking for ways to optimize a password cracker I had been making, I came across a much shorter implementation of all possible character combinations in a list, which used this function: mapM (const xs) [1..n] where xs could be the characters available, and n the length of the desired words. so mapM (const "abcd") [1..4] would output a list ["aaaa","aaab","aaac","aaad","aaba","aabb"..] and so on. Only the length matters for the list of th right, I could have written ['f','h','s'

How to return last element in the list using function in haskell?

心不动则不痛 提交于 2020-12-08 05:15:10
问题 My professor gave me an example to get last element in the list using " laste " function: he stated that: definition in the form of “ laste xs = … ” is not acceptable, whereas definition in the form of “ laste = … ” is acceptable. I have tried something like this: Please correct me if my solution is wrong according to problem statement. laste :: [a] -> Maybe a laste [] = Nothing laste (x:[]) = Just x laste (x:xs) = laste xs But this gives me answer for example: ghci>laste[1,2,3,4] Just 4 I

How to return last element in the list using function in haskell?

孤者浪人 提交于 2020-12-08 05:13:43
问题 My professor gave me an example to get last element in the list using " laste " function: he stated that: definition in the form of “ laste xs = … ” is not acceptable, whereas definition in the form of “ laste = … ” is acceptable. I have tried something like this: Please correct me if my solution is wrong according to problem statement. laste :: [a] -> Maybe a laste [] = Nothing laste (x:[]) = Just x laste (x:xs) = laste xs But this gives me answer for example: ghci>laste[1,2,3,4] Just 4 I

Prolog implementation of Quine's algorithm for classical propositional logic (in Quine's “Methods of Logic”)

旧城冷巷雨未停 提交于 2020-12-05 05:00:05
问题 I know only one prover that translates the algorithm that Quine gave for classical propositional logic in his book Methods of Logic (Harvard University Press, 1982, ch. 1 sec. 5, pp. 33-40), this prover is in Haskell and it is here: Quine's algorithm in Haskell I tried to translate Quine's algorithm in Prolog, but until now I have not succeeded. It is a pity because it is an efficient algorithm and a Prolog translation would be interesting. I am going to describe this algorithm. The only

Why can't I pattern match on the concatenation function (++) in Haskell?

本秂侑毒 提交于 2020-12-03 05:56:27
问题 I'm trying to match **String Newline String** pattern in a function Split. split::String -> [String] split[] = [] split (x++'\n':xs) = [x]++split(xs) I'm getting this error: Parse error in pattern: x ++ ('\n' : xs) What am I doing wrong here? I know there are other ways of achieving the same result but I'd like to understand what wrong with this pattern. I'm fairly new to Haskell BTW. 回答1: One problem (as I understand it) is that ++ is not a constructor of the list data type the way : is. You

Haskell Cabal package - can't find Paths_ module

只谈情不闲聊 提交于 2020-12-02 07:28:12
问题 I'm working on a Haskell project (Happstack server + Blaze HTML/front-end as main libraries) and I want to add a static data directory. Looks like you can do so with Cabal using the auto-generated Path_<package_name> module. So in my example, the package is called new-website , so that module should be called Paths_new_website . Link to Cabal docs re: a custom package's Paths_pkgname module. From the command line and using cabal repl , I am trying to confirm that I'll have access to the Paths

How to write a lisp parser in Haskell?

本小妞迷上赌 提交于 2020-12-01 11:32:28
问题 I'm trying to write a lisp interpreter in haskell, inspired by Norvig's in Python (http://norvig.com/lispy.html). I have a successful tokenizer which I can link to if need be. Here it outputs the correct code up to Norvig's Python tokenizer. program = "(begin (define r 10) (* pi (* r r)))" astTokenized = tokenize program astTokenized == ["(","begin","(","define","r","10",")","(","*","pi","(","*","r","r",")",")",")"] Here I define my abstract syntax tree data type, although I know that it