ghci

Defining function signature in GHCi

℡╲_俬逩灬. 提交于 2020-01-12 07:08:11
问题 Defining a function signature in Haskell's interpreter GHCi doesn't work. Copying an example from this page: Prelude> square :: Int -> Int <interactive>:60:1: error: • No instance for (Show (Int -> Int)) arising from a use of ‘print’ (maybe you haven't applied a function to enough arguments?) • In a stmt of an interactive GHCi command: print it Prelude> square x = x * x How can I declare a function signature and then give function definition in Haskell interactively? also: why can't I simply

How can I view the definition of a function in Haskell/GHCi?

拈花ヽ惹草 提交于 2020-01-11 18:04:15
问题 I'm using Haskell 2010.1.0.0.1 with GHC 6. Typing :t at the GHCi prompt followed by the name of a function shows us the type of the function. Is there a way to view the function definition as well? 回答1: Not currently. The closest command to what you want is :info :info name ... Displays information about the given name(s). For example, if name is a class, then the class methods and their types will be printed; if name is a type constructor, then its definition will be printed; if name is a

Access violation in GHCI

不问归期 提交于 2020-01-06 04:37:14
问题 I have a Haskell program using the FFI to import C++ functions. I'm using Windows. When I compile to an executable or to a DLL, this works. But when I load a module in GHCI, this doesn't always work: sometimes this works, sometimes I get Access violation in generated code when reading 0000000000000000 whenever I call a function from the module (even if this function has nothing to do with the C++). Do you know how to prevent that? 来源: https://stackoverflow.com/questions/47849032/access

How to be certain that all threads have been killed upon pressing Ctrl+C

淺唱寂寞╮ 提交于 2020-01-05 07:10:30
问题 I'm running a servant server and another background thread (via async ) in gchi . When I press Ctrl+c on the GHCi prompt, the servant server shuts down properly, but my background thread keeps running. Only quitting the entire GHCi session seems to really terminate it. Two questions: Is this behaviour only because I'm in GHCi? If I compiled a binary, ran it, and then pressed Ctrl+C on it, would the background-thread still keep running? How do I solve for this properly? 回答1: Is this behaviour

How to be certain that all threads have been killed upon pressing Ctrl+C

时光总嘲笑我的痴心妄想 提交于 2020-01-05 07:09:18
问题 I'm running a servant server and another background thread (via async ) in gchi . When I press Ctrl+c on the GHCi prompt, the servant server shuts down properly, but my background thread keeps running. Only quitting the entire GHCi session seems to really terminate it. Two questions: Is this behaviour only because I'm in GHCi? If I compiled a binary, ran it, and then pressed Ctrl+C on it, would the background-thread still keep running? How do I solve for this properly? 回答1: Is this behaviour

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

Why does `peek` with a polymorphic Ptr return GHC.Prim.Any when used with a bind?

老子叫甜甜 提交于 2020-01-02 08:38:25
问题 Using the low-level GNU Science Library bindings Bindings.Gsl.RandomNumberGeneration, I'm running into this odd type behavior in GHCi where binding changes return type from a peek into GHC.Prim.Any . I'm trying to understand why since I can't use the c'rng_alloc unless I retain the type of pointer to an rng . For eample: λ> :t c'gsl_rng_alloc c'gsl_rng_alloc :: Ptr C'gsl_rng_type -> IO (Ptr C'gsl_rng) λ> :t p'gsl_rng_mt19937 p'gsl_rng_mt19937 :: Ptr (Ptr gsl_rng_type) λ> :t peek p'gsl_rng

Why can ghci see non-exported types and constructors? How can I fix it?

南楼画角 提交于 2020-01-02 04:04:14
问题 I am a novice in Haskell. Here's some simple code: module Src ( -- The 'Answer' type isn't exported Shape(Circle), -- i.e 'Rectangle' data constructor isn't exported Point(..), area, nudge ) where data Answer = Yes | No deriving (Show) data Point = Point Float Float deriving (Show) data Shape = Circle Point Float | Rectangle Point Point deriving (Show) area :: Shape -> Float area (Circle _ r) = pi * r ^ 2 area (Rectangle (Point x1 y1) (Point x2 y2)) = (abs $ x2 - x1) * (abs $ y2 - y1) nudge:

How to make Haskell or ghci able to show Chinese characters and run Chinese characters named scripts?

为君一笑 提交于 2020-01-01 04:24:08
问题 I want to make a Haskell script to read files in my /home folder. However there are many files named with Chinese characters, and Haskell and Ghci cannot manage it. It seems Haskell and Ghci aren't good at displaying UTF-8 characters. Here is what I encountered: Prelude> "让Haskell或者Ghci能正确显示汉字并且读取汉字命名的文档" "\35753Haskell\25110\32773Ghci\33021\27491\30830\26174\31034\27721\23383\24182\19988\35835\21462\27721\23383\21629\21517\30340\25991\26723" 回答1: Prelude> putStrLn "\35753Haskell\25110