haskell

Identity of simulation objects in Haskell

拟墨画扇 提交于 2020-01-04 01:51:29
问题 Writing a simulation in an object-oriented language, each object has an identity--that is, a way to distinguish it from every other object in the simulation, even if other objects have the exact same attributes. An object retains its identity, no matter how much it changes over time. This is because each object has a unique location in memory, and we can express that location with pointers or references. This works even if you don't impose an additional identity system like GUIDs. (Which you

GHC Foreign hs_init/hs_add_root crashes

孤街浪徒 提交于 2020-01-03 21:48:09
问题 I don't repeat more than necessary, brief summary: Following the Adder example from this tutorial on a machine with win7 (64) with VS 2010. But I don't use C++ but plain C. When using the cl (MS compiler) with cl /Zi (and no other flag) it works like expected. If not use /Zi and then try to execute the exe goes into flames. Why? (There must be some compiler/link options that make some init in the start of the haskell dll go wrong ) EDIT: Some investigation: /Zi does not affect optimizations.

GHC Foreign hs_init/hs_add_root crashes

廉价感情. 提交于 2020-01-03 21:47:04
问题 I don't repeat more than necessary, brief summary: Following the Adder example from this tutorial on a machine with win7 (64) with VS 2010. But I don't use C++ but plain C. When using the cl (MS compiler) with cl /Zi (and no other flag) it works like expected. If not use /Zi and then try to execute the exe goes into flames. Why? (There must be some compiler/link options that make some init in the start of the haskell dll go wrong ) EDIT: Some investigation: /Zi does not affect optimizations.

I'm not sure I understand the type definition of the foldl function in haskell

ⅰ亾dé卋堺 提交于 2020-01-03 19:58:50
问题 When I ask about the foldl type, what I see is this: *Main> :t foldl foldl :: Foldable t => (b -> a -> b) -> b -> t a -> b In this case, what is t a ? I guess it means that the function is using a Foldable parametrized with a but I'm not even really sure about the syntax. For instance, why can't I substitute t a with Foldable a ? And, bonus question, if I had to define foldl myself, I would start with the base case foldl f b [] = [] But if the base case takes a list, than it would not make

Hint.interpret gives a compiler error when used on a Polysemy.Sem value

你。 提交于 2020-01-03 19:37:16
问题 The bounty expires in 3 days . Answers to this question are eligible for a +50 reputation bounty. ShapeOfMatter wants to draw more attention to this question: “I'm still not sure how to move forward on this.” I'm trying to compile Polysemy monad values at runtime using Hint (Language.Haskell.Interpreter). When I try to do this I reliably get an error about improper use of the : operator in "interactive" code; it seems as if the text hint is passing to GHC has a syntax error in it. {-#

Hint.interpret gives a compiler error when used on a Polysemy.Sem value

这一生的挚爱 提交于 2020-01-03 19:34:56
问题 The bounty expires in 3 days . Answers to this question are eligible for a +50 reputation bounty. ShapeOfMatter wants to draw more attention to this question: “I'm still not sure how to move forward on this.” I'm trying to compile Polysemy monad values at runtime using Hint (Language.Haskell.Interpreter). When I try to do this I reliably get an error about improper use of the : operator in "interactive" code; it seems as if the text hint is passing to GHC has a syntax error in it. {-#

What recursion scheme should I use to repeat an effectful action until its result matches some criterion?

北城以北 提交于 2020-01-03 19:04:18
问题 That is, what I am asking about is a loop. effectful :: Int -> IO Int effectful n = do putStrLn $ "Effect: " ++ show n return n condition = (== 3) final :: Int -> IO () final n = putStrLn $ "Result: " ++ show n loop = ? It should work like this: λ loop [1..10] Effect: 1 Effect: 2 Effect: 3 Result: 3 I can offer a recursive definition: loop (x: xs) = do r <- effectful x if condition r then final r else loop xs However, I am having trouble representing this effect with any combination of

Haskell list frozen

家住魔仙堡 提交于 2020-01-03 19:04:15
问题 I'm new to Haskell and playing around trying to understand a few things. If I do the following I receive a problem: list1 = [1..] list2 = [x | x <- list1, x <= 4] print list2 which returns [1,2,3,4 . There isn't an end bracket on it, so it is as if the list is loading or frozen. Here is how it looks: Prelude> print list2 [1,2,3,4 What is going on here? 回答1: You know that the list is monotonically increasing, but Haskell does not. Use takeWhile , instead of a list comprehension, so that list1

When are MVar operations guaranteed to be uninterruptible?

倾然丶 夕夏残阳落幕 提交于 2020-01-03 18:55:08
问题 The documentation for Control.Exception describes which operations can have async exceptions thrown, even within a mask ed block, saying: "The following operations are guaranteed not to be interruptible" takeMVar if the MVar is definitely full, and conversely putMVar if the MVar is definitely empty In what cases is an MVar "definitely" full or empty from the compiler's point of view? Is that even well-enough defined to enable reasoning about whether my code will break without handling async

When are MVar operations guaranteed to be uninterruptible?

孤街醉人 提交于 2020-01-03 18:55:06
问题 The documentation for Control.Exception describes which operations can have async exceptions thrown, even within a mask ed block, saying: "The following operations are guaranteed not to be interruptible" takeMVar if the MVar is definitely full, and conversely putMVar if the MVar is definitely empty In what cases is an MVar "definitely" full or empty from the compiler's point of view? Is that even well-enough defined to enable reasoning about whether my code will break without handling async