ghci

Debugging IO in a package module inside GHCi

喜你入骨 提交于 2019-12-20 11:33:32
问题 I'm doing low-level IO (for library bindings) in Haskell and am experiencing a segfault. I would like to use GHCi's :break to figure out what's going on, but here's what happens: > import SDL > :break SDL.setPaletteColors cannot set breakpoint on setPaletteColors: module SDL.Video.Renderer is not interpreted Since the offending code is not inside my own modules, but rather inside a module in an external package, it's loaded as compiled code and apparently I can't use :break on compiled

How do I use cabal's MIN_VERSION_ and other macros with ghci?

半腔热情 提交于 2019-12-20 10:23:48
问题 When I use Cabal's various MIN_VERSION_ macros in a Haskell project, how can I ensure they are all correctly defined when I am not using cabal, e.g. when testing in GHCi? 回答1: Nowadays, cabal supports a cabal repl subcommand, which does all the setup for you, so at least for ghci the following is unnecessary. Nevertheless: The cabal build command generates the file dist/build/autogen/cabal_macros.h , which contains all the definitions you need. In order to include that file in a ghc

Difference in performance of compiled accelerate code ran from ghci and shell

左心房为你撑大大i 提交于 2019-12-20 10:19:09
问题 Problem Hello, I'm using accelerate library to create an application allowing the user to interactively call functions that process images, that's why I'm basing on and extending ghci using ghc api. The problem is that when running the compiled executable from the shell the computations are done under 100ms (slightly less than 80), while running the same compiled code within ghci it takes over 100ms (on average a bit more than 140) to finish. Resources sample code + execution logs: https:/

Set prompt in Haskell

三世轮回 提交于 2019-12-20 05:45:22
问题 I'm new in Haskell Instead of the: Prelude> I want GHCi to prompt GHCi> I wrote :set prompt "GHCi> " but when I close GHCi and open it again it show me prelude again. I saw that I need to create a file called .ghci in my home folder and set its to contents to :set prompt "GHCi> ". How can I create this file and set the prompt. Thank You for your answers 回答1: You can make a .ghci file that specifies the configuration of your GHCi environment. For a *nix system, that is often located at the ~/

Memoization pascals triangle

孤街醉人 提交于 2019-12-20 05:00:12
问题 I'm not interested in the actual solution or other methods solving the problem, it's the memoization i need help with :) I need help doing a pascals triangle problem with memoization. I want to get the middle number in the base of the triangle. (Project Euler 15) The first example is not memoized (although the name suggests so) "20 20" not solvable Second attempt is an attempt on doing something similar to: http://www.haskell.org/haskellwiki/Memoization Third is hlints suggestion on no2 if

Compiling Haskell code in Cygwin, and some other bugs in Haskell Platform on Windows

五迷三道 提交于 2019-12-19 19:53:29
问题 I am trying to compile a simple hello world program in Haskell, with Haskell Platform 2011.2.0.1. If I load the code in WinGHCi, and use the GUI to compile, the .exe is created. Then I can run the .exe from Cygwin. But if I try to compile the code in Cygwin (using ghc --make ), linker fails. But again, if I compile from the Windows cmd prompt, then the compile+linker works fine. Are there any other environment variables I need to import into Cygwin, to make the compile+linker work in it? I

How can I build a ThreadId given that I know the actual number?

时光毁灭记忆、已成空白 提交于 2019-12-19 19:51:29
问题 It often happens to me when debugging or playing around in GHCi that I happen to know the actual ThreadId number (for example from using Debug.Trace ), but that's all I have. The problem is that all thread APIs, such as killThread require a ThreadId and not an Int . I've tried Hoogle but came out empty. Is there a way to do this? I'm concerned mostly with debugging, so I don't mind if it's a nasty hack or if it's through a GHC-only library. 回答1: You can't. ThreadId is abstract. The Int you

How can i get the type of a polymorphic function for a specific type class instance?

帅比萌擦擦* 提交于 2019-12-19 18:22:13
问题 For example, typing :t ap in GHCi gives the result ap :: Monad m => m (a -> b) -> m a -> m b If I already know the Monad instance I'm going to use is ((->) r) , how can I query for the type of ap for that specific instance? 回答1: You can use visible type application feature to specify parametric types. You can look at functions in more creative way: functions in Haskell can be applied to not only values of some types, but also to types of that values. But to pass type you should somehow

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

旧巷老猫 提交于 2019-12-19 05:23:52
问题 Is it possible to query the ghci for the type it inferred for a function inside another function? 回答1: 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

Infinite loop in haskell? (newbie)

感情迁移 提交于 2019-12-19 05:06:13
问题 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! 回答1: 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