ghci

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

点点圈 提交于 2019-12-02 23:28:08
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://gist.github.com/zgredzik/15a437c87d3d8d03b8fc Description First of all: the tests were ran after the CUDA

How to set a program's command line arguments for GHCi?

梦想与她 提交于 2019-12-02 17:28:10
Suppose some Haskell file is executed with runghc Queens.hs gecode_compile Now, this fails, and I want to debug it with ghci . How do I pass the option gecode_compile into the program, so getArgs will read it correctly? Thanks!! You can also set the command line arguments in ghci ghci> :set args foo bar ghci> main or ghci> :main foo bar You can use the System.Environment.withArgs function to execute main with your desired arguments. Here's an example session (irrelevant details elided): $ ghci GHCi, version 7.0.3: http://www.haskell.org/ghc/ :? for help Prelude> import System.Environment

Which is the type of (flip .)?

允我心安 提交于 2019-12-02 08:10:25
I'm trying to understand why the type of: (flip .) is: (a -> a1 -> b -> c) -> a -> b -> a1 -> c First of all, the type of: flip: is (a -> b -> c) -> b -> a -> c (.): is (b -> c) -> (a -> b) -> a -> c I will rename the variables to be more clear in my explanation, so the types: flip: is (ax -> bx -> cx) -> bx -> ax -> cx (.): is (by -> cy) -> (ay -> by) -> ay -> cy Then I try substituing like this: ax = (by -> cy) bx = (ay -> by) cx = ay -> cy So the resulting type is: (ay -> by) (by -> cy) -> ay -> cy, which is different with the correct result. Any help? Thanks, Sebastián. (flip .) is (.)

Why does the type of a function change when it comes out of a monad in GHCi [duplicate]

孤者浪人 提交于 2019-12-02 03:56:26
问题 This question already has an answer here : Why does `peek` with a polymorphic Ptr return GHC.Prim.Any when used with a bind? (1 answer) Closed 3 years ago . Something changes about the type of a function when it comes out of a monad. In GHCI: > :t map map :: (a -> b) -> [a] -> [b] > a <- return map > :t a a :: (GHC.Prim.Any -> GHC.Prim.Any) -> [GHC.Prim.Any] -> [GHC.Prim.Any] This change makes it hard to store the function in a higher rank type. What is happening here and can I make it not

Memoization pascals triangle

 ̄綄美尐妖づ 提交于 2019-12-02 03:46:51
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 that is more readable for someone. I get this error, but i'm not sure its right even if it would compile.

Why does the type of a function change when it comes out of a monad in GHCi [duplicate]

你离开我真会死。 提交于 2019-12-02 01:39:00
This question already has an answer here: Why does `peek` with a polymorphic Ptr return GHC.Prim.Any when used with a bind? 1 answer Something changes about the type of a function when it comes out of a monad. In GHCI: > :t map map :: (a -> b) -> [a] -> [b] > a <- return map > :t a a :: (GHC.Prim.Any -> GHC.Prim.Any) -> [GHC.Prim.Any] -> [GHC.Prim.Any] This change makes it hard to store the function in a higher rank type. What is happening here and can I make it not happen? (Also doesn't this violate one of the monad laws?) First of all, there is no point in doing anything like a <- return map

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

流过昼夜 提交于 2019-12-01 18:15:46
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 have put the following dirs in my Cygwin PATH: 2011.2.0.1/lib/extralibs/bin , 2011.2.0.1/bin (these are

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

僤鯓⒐⒋嵵緔 提交于 2019-12-01 17:44:07
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. You can't. ThreadId is abstract. The Int you have is actually nothing more than a counter ( source ): 32 static StgThreadID next_thread_id = 1; ... 59

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

本秂侑毒 提交于 2019-12-01 17:31:58
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? Shersh 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 specify (with prepending @ ) that you're passing types (because types are not first-class objects in

ghci - defaulting confusion

痴心易碎 提交于 2019-12-01 17:27:47
问题 I happened to see some strange behaviour during checking the size ( minBound , maxBound ) and "length in decimal representation" of different integral types. Using GHCi: Prelude> :{ Prelude| let mi = minBound Prelude| ma = maxBound Prelude| le = fromIntegral $ length $ show ma Prelude| in [mi,ma,le] :: [Int] Prelude| :} [-9223372036854775808,922372036854775807,2] ^ in the last place I would expect 19 . My first guess is that maxBound defaults to () and thus yields 2 , but I don't understand