ghci

Is there a way to limit the memory, ghci can have?

血红的双手。 提交于 2019-11-27 17:45:28
问题 I'm used to debug my code using ghci. Often, something like this happens (not so obvious, of course): ghci> let f@(_:x) = 0:1:zipWith(+)f x ghci> length f Then, nothing happens for some time, and if I don't react fast enough, ghci has eaten maybe 2 GB of RAM, causing my system to freeze. If it's too late, the only way to solve this problem is [ALT] + [PRINT] + [K]. My question: Is there an easy way to limit the memory, which can be consumed by ghci to, let's say 1 GB? If limit is exceed, the

How do I use multiple where clauses in GHCi?

吃可爱长大的小学妹 提交于 2019-11-27 17:22:41
问题 I'm playing around with GHCi for the first time, and I'm having some trouble writing multi-line functions. My code is as follows: Prelude> :{ Prelude| let diffSquares lst = abs $ squareOfSums lst - sumOfSquares lst Prelude| where Prelude| squareOfSums lst = (fst (sumsAndSquares lst))^2 Prelude| sumOfSquares lst = snd (sumsAndSquares lst) Prelude| sumsAndSquares = foldl (\(sms,sqrs) x -> (sms+x,sqrs+x^2)) (0,0) Prelude| :} It gives the following error: <interactive>:1:142: parse error on input

IO/Monadic assign operator causing ghci to explode for infinite list

吃可爱长大的小学妹 提交于 2019-11-27 15:53:17
问题 Consider the following program. It runs forever and does nothing useful, but the memory consumption in ghci is constant : --NoExplode.hs module Main (main) where test :: [Int] -> IO() test lst = do print "test" rList lst rList :: [Int] -> IO () rList [] = return () rList (x:xs) = do rList xs main = do test [1..] Now consider the following trivially modified version of the above. When this program is run in ghci the memory explodes. The only difference is that print "test" is now assigned to x

How can I set my GHCi prompt to a lambda character on Windows?

落花浮王杯 提交于 2019-11-27 13:44:39
问题 I want to have a lambda (λ) symbol as my prompt in GHCi (7.8) on Windows 7, so I set up my .ghci file as :set +m :set prompt "λ: " :set prompt2 " | " And I set my console font to Lucida Console since it's supposed to support Unicode, but when I load up GHCi, it looks like this instead How can I get Windows to recognize the λ symbol properly? 回答1: Using > chcp.com 65001 worked with ghci but opening other text files with vim after setting that code page returned garbled text. Add the following

I taught ghci to compile my StackOverflow posts. Can I make it slicker?

橙三吉。 提交于 2019-11-27 11:07:09
问题 Haskell Stack Overflow layout preprocessor module StackOverflow where -- yes, the source of this post compiles as is Skip down to What to do to get it working if you want to play with this first (1/2 way down). Skip down to What I would like if I witter on a bit and you just want to find out what help I'm seeking. TLDR Question summary: Can I get ghci to add filename completion to the :so command I defined in my ghci.conf ? Could I somehow define a ghci command that returns code for

Why :sprint always prints a “_”?

僤鯓⒐⒋嵵緔 提交于 2019-11-27 09:14:26
Prelude> let a = 3 Prelude> :sprint a a = _ Prelude> let c = "ab" Prelude> :sprint c c = _ Why does it always print a _ ? I don't quite get the semantics of the :sprint command. Haskell is a lazy language. It doesn't evaluate results until they are "needed". Now, just printing a value causes all of it to be "needed". In other words, if you type an expression in GHCi, it will try to print out the result, which causes it all to be evaluated. Usually that's what you want. The sprint command (which is a GHCi feature, not part of the Haskell language) allows you to see how much of a value has been

What is going on with the types in this ghci session?

北城余情 提交于 2019-11-27 06:36:00
问题 I'm learning Haskell, and I was playing around in ghci when I came across something very puzzling. First, create a simple add function: Prelude> let add x y = x + y Note that it works with ints and floats: Prelude> add 3 4 7 Prelude> add 2.5 1.3 3.8 Now create an apply function. It's identical to $ (but not infix). It works like a no-op on add: Prelude> let apply f x = f x Prelude> apply add 3 4 7 Prelude> apply add 2.5 1.3 3.8 Ok, now make add' which is the same as add' but using apply :

Why does ghci say that 1.1 + 1.1 + 1.1 > 3.3 is True?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 06:11:09
问题 I've been going through a Haskell tutorial recently and noticed this behaviour when trying some simple Haskell expressions in the interactive ghci shell: Prelude> 1.1 + 1.1 == 2.2 True Prelude> 1.1 + 1.1 + 1.1 == 3.3 False Prelude> 1.1 + 1.1 + 1.1 > 3.3 True Prelude> 1.1 + 1.1 + 1.1 3.3000000000000003 Does anybody know why that is? 回答1: Because 1.1 and 3.3 are floating point numbers. Decimal fractions, such as .1 or .3, are not exactly representable in a binary floating point number. .1 means

Prefix form of unary operator in Haskell

本小妞迷上赌 提交于 2019-11-27 05:38:01
In GHCi: Prelude> (+3) 2 5 Prelude> (*3) 2 6 Prelude> (/3) 2 0.6666666666666666 Prelude> (-3) 2 No instance for (Num (t -> t1)) arising from the literal 3' at <interactive>:1:2 Possible fix: add an instance declaration for (Num (t -> t1)) In the expression: 3 In the expression: (- 3) 2 In the definition of it': it = (- 3) 2 How can I correct the last one to make it return -1? Haskell's grammar doesn't allow you to use - like that. Use the subtract function instead: (subtract 3) 2 Travis Brown As a footnote to grddev's answer , here's the relevant paragraph from the Haskell 98 Report : The

GHCi “let” — what does it do?

限于喜欢 提交于 2019-11-27 04:23:21
问题 I'd appreciate is someone could point to docs on what "let" does in GHCi, or failing that, explain it convincingly :-). So far as I can tell, "let" (without "in") is not part of the Haskell language per se, and on the other hand, it doesn't appear to be a GHCI command either, as it's not prefixed by colon. 回答1: While programming in GHCi, you're like programming in the IO monad with do syntax, so for example you can directly execute an IO action, or use monadic bind syntax like r <- someIOFun