ghci

GHCi hangs when Ctrl+Cing from infinite loop with -fbreak-on-exception set

ε祈祈猫儿з 提交于 2019-12-01 16:08:46
As the title says, I create an infinite loop in GHCi: f x = x - 2 g x = if f x < x then g (f x + 2) else x g 2 Normally pressing Ctrl+C yields "Interrupted." and a return to the GHCi prompt. If I :set -fbreak-on-exception beforehand though, Ctrl+C does not break the loop and my only recourse is to kill the program externally. Is there a way to break into infinite loops using GHCi? Is this a bug? 来源: https://stackoverflow.com/questions/47188857/ghci-hangs-when-ctrlcing-from-infinite-loop-with-fbreak-on-exception-set

have ghci list all possible type class instances?

别等时光非礼了梦想. 提交于 2019-12-01 15:48:15
When ghc can't determine a concrete type class instance, you'll get a message like: No instance for ... arising from a use of `it' The type variable `a0' is ambiguous Possible fix: add a type signature that fixes these type variable(s) Note: there are several potential instances: (lists a few instances) ...plus 13 others Possible fix: ... Is there way to display all of the defined instances of a type class? You can use the :info command (shortened to :i ) to do this: > :i Num class Num a where (+) :: a -> a -> a (*) :: a -> a -> a (-) :: a -> a -> a negate :: a -> a abs :: a -> a signum :: a -

GHCi hangs when Ctrl+Cing from infinite loop with -fbreak-on-exception set

烈酒焚心 提交于 2019-12-01 15:06:17
问题 As the title says, I create an infinite loop in GHCi: f x = x - 2 g x = if f x < x then g (f x + 2) else x g 2 Normally pressing Ctrl+C yields "Interrupted." and a return to the GHCi prompt. If I :set -fbreak-on-exception beforehand though, Ctrl+C does not break the loop and my only recourse is to kill the program externally. Is there a way to break into infinite loops using GHCi? Is this a bug? 来源: https://stackoverflow.com/questions/47188857/ghci-hangs-when-ctrlcing-from-infinite-loop-with

have ghci list all possible type class instances?

可紊 提交于 2019-12-01 14:43:51
问题 When ghc can't determine a concrete type class instance, you'll get a message like: No instance for ... arising from a use of `it' The type variable `a0' is ambiguous Possible fix: add a type signature that fixes these type variable(s) Note: there are several potential instances: (lists a few instances) ...plus 13 others Possible fix: ... Is there way to display all of the defined instances of a type class? 回答1: You can use the :info command (shortened to :i ) to do this: > :i Num class Num a

GHCi doesn't work with FFI export declarations/shared libraries

余生长醉 提交于 2019-12-01 04:35:41
I have a problem regarding FFI in Haskell and the interactive mode of GHC. (Source is also available via a gist ): FFISo.hs: {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ForeignFunctionInterface #-} module Main where import qualified Data.ByteString.Char8 as B foreign import ccall "callMeFromHaskell" callMeFromHaskell :: IO () foreign export ccall callMeFromC :: IO () callMeFromC :: IO () callMeFromC = B.putStrLn "callMeFromC" main :: IO () main = do B.putStrLn "main" callMeFromHaskell return () c.c: #include <stdio.h> void callMeFromC(void); void callMeFromHaskell(void) { printf(

ghci self-referencing assignment

眉间皱痕 提交于 2019-12-01 04:18:15
I was learning some new Haskell today, when I tried something in ghci. It basically boiled down to this: Prelude> let x = 6 Prelude> x 6 Prelude> let y = show x Prelude> y "6" Prelude> let x = show x Prelude> x "\"\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\" --(repeats) So can ghci not self-reference in assignment? I feel like it's akin to i = i++; in C, or trying to reference previous assignments of a let (not let* ) in Scheme. Is there anyway to do this, or should I just use the easier let y = show x ? Definitions in Haskell are recursive by

What does [safe] marker mean in ghci?

纵然是瞬间 提交于 2019-12-01 04:05:08
Prelude Data.Void> :info Void data Void -- Defined in `Data.Void' instance [safe] Eq Void -- Defined in `Data.Void' instance [safe] Ord Void -- Defined in `Data.Void' instance [safe] Read Void -- Defined in `Data.Void' instance [safe] Show Void -- Defined in `Data.Void' What does [safe] mean? It simply means that the datatype is defined in a module which is defined using safe extension. You can find the details of the extension in the user guide . In fact, you can test that yourself by defining a module using the Safe extension: {-#LANGUAGE Safe#-} data Test = Test deriving (Eq, Show) And then

Haskell: Function application with $

最后都变了- 提交于 2019-12-01 03:31:24
In the following snippet, you can see my two collatz functions I wrote in Haskell. For the recursive application I used parentheses in the first example (collatz) to get the right precedence. As I have just learnt function application with $, I tried to rewrite the function (collatz') using that thing. However, I encounter the following error: Couldn't match expected type `[a]' against inferred type `a1 -> [a1]' In the second argument of `(:)', namely `collatz'' In the first argument of `($)', namely `n : collatz'' In the expression: n : collatz' $ n `div` 2 collatz :: (Integral a) => a -> [a]

Can GHCi tell me the type of a local Haskell function?

旧街凉风 提交于 2019-12-01 03:24:07
Is it possible to query the ghci for the type it inferred for a function inside another function? This is a quick and ugly hack, but what I usually do is just use the function in the wrong way and read the error message: inc x = x + 1 where f (y, z) = y + z g = f :: Char GHCi output: Couldn't match expected type `Char' against inferred type `(t, t) -> t' In the expression: f :: Char Although this leaves out the context Num t => , this usually does provide me with enough information to continue. You might try doing it by setting a breakpoint on it, so the function is in scope from the debugger.

Infinite loop in haskell? (newbie)

老子叫甜甜 提交于 2019-12-01 02:46:43
I'm just learning Haskell. I thought this would produce a factorial function... (within ghci) Prelude> let ft 0 = 1 Prelude> let ft n = n * ft (n - 1) Prelude> ft 5 (hangs indefinitely, until ^C). Can someone point me in the right direction? Thanks! The two separate let statements are interpreted independently from each other. First a function ft 0 = 1 is defined, and then a new function ft n = n * ft (n - 1) is defined, overwriting the first definition. To define one function with two cases you have to put both cases into a single let statement. To do this in a single line at the GHCI prompt