haskell

can't get wxHaskell to work from ghci on Mac

佐手、 提交于 2020-01-02 03:40:19
问题 I'm trying to run an example using EnableGUI function. % ghci -framework Carbon Main.hs *Main> enableGUI >> main This is what I get instead of a working program: 2013-01-14 00:21:03.021 ghc[13403:1303] *** Assertion failure in +[NSUndoManager _endTopLevelGroupings], /SourceCache/Foundation/Foundation-945.11/Misc.subproj/NSUndoManager.m:328 2013-01-14 00:21:03.022 ghc[13403:1303] +[NSUndoManager(NSInternal) _endTopLevelGroupings] is only safe to invoke on the main thread. 2013-01-14 00:21:03

How do I figure out which of my imports are from in Haskell?

情到浓时终转凉″ 提交于 2020-01-02 03:35:19
问题 I have a bunch of imports in my package and need to sort out which ones are coming from a specific package (MissingH). I'm not sure how to do this other than by searching for each on Hoogle. Is there a way to do this programmatically or at the command line by just scanning my package's files? Here's my list of imports (from all files of my package): import Control.Arrow import Control.Exception (assert) import Control.Monad (unless) import Control.Monad.Except import Control.Monad.Zip import

Haskell: I/O and Returning From a Function

最后都变了- 提交于 2020-01-02 03:29:08
问题 Please bear with me as I am very new to functional programming and Haskell. I am attempting to write a function in Haskell that takes a list of Integers, prints the head of said list, and then returns the tail of the list. The function needs to be of type [Integer] -> [Integer]. To give a bit of context, I am writing an interpreter and this function is called when its respective command is looked up in an associative list (key is the command, value is the function). Here is the code I have

Haskell Parsec Parser for Encountering […]

柔情痞子 提交于 2020-01-02 03:29:07
问题 I'm attempting to write a parser in Haskell using Parsec. Currently I have a program that can parse test x [1,2,3] end The code that does this is given as follows testParser = do { reserved "test"; v <- identifier; symbol "["; l <- sepBy natural commaSep; symbol "]"; p <- pParser; return $ Test v (List l) p } <?> "end" where commaSep is defined as commaSep = skipMany1 (space <|> char ',') Now is there some way for me to parse a similar statement, specifically: test x [1...3] end Being new to

Inverse of the absurd function

China☆狼群 提交于 2020-01-02 03:17:09
问题 Is there an inverse to the absurd function from Data.Void ? If it exists, how is it implemented and what is it used for? 回答1: This function does not exist. (assuming strict semantics) Looking at the algebra of types, the function type is equivalent to exponentiation. Now the function absurd , which has the type Void -> a corresponds to the operation a ^ 0 which equals 1 . This means that there is exactly one implementation of absurd , which can be found in Data.Void . Reversing the arrow, you

Remove every nth element from string

淺唱寂寞╮ 提交于 2020-01-02 02:33:32
问题 How can you remove every nth element of a string? I'm guessing you would use the drop function in some kind of way. Like this drops the first n, how can you change this so only drops the nth, and then the nth after that, and so on, rather than all? dropthem n xs = drop n xs 回答1: remove_every_nth :: Int -> [a] -> [a] remove_every_nth n = foldr step [] . zip [1..] where step (i,x) acc = if (i `mod` n) == 0 then acc else x:acc Here's what the function does: zip [1..] is used to index all items

Haskell type family instance with type constraints

女生的网名这么多〃 提交于 2020-01-02 02:33:11
问题 I am trying to represent expressions with type families, but I cannot seem to figure out how to write the constraints that I want, and I'm starting to feel like it's just not possible. Here is my code: class Evaluable c where type Return c :: * evaluate :: c -> Return c data Negate n = Negate n instance (Evaluable n, Return n ~ Int) => Evaluable (Negate n) where type Return (Negate n) = Return n evaluate (Negate n) = negate (evaluate n) This all compiles fine, but it doesn't express exactly

Recommended approach to use Stack as global package manager

最后都变了- 提交于 2020-01-02 02:15:08
问题 I would like to install some Haskell libraries globally, for example hindent which is used by my editor's Haskell integration. What is the recommended way to do this? I thought that stack install hindent was the correct way to do this. However, then I wanted to update my packages and found that there was no way to do this . According to the GitHub issue report I found, stack is concerned with managing a local build sandbox for a project. It isn't intended to be a global package manager. There

How to create a non-TH package from code generated using Template Haskell?

一笑奈何 提交于 2020-01-02 02:04:08
问题 I'm making a small package that defines wrappers for tuples and adds instances form them, like newtype Tuple2 a = Tuple2 { untuple2 :: (a, a) } deriving (...) tuple2 :: a -> a -> Tuple2 a tuple2 = ... instance Traversable Tuple2 where ... instance Foldable Tuple2 where ... instance Functor Tuple2 where ... instance Applicative Tuple2 where ... This repeats from 2 to 15, so it looks like a job for Template Haskell. The generated code is always Haskell 98 compatible, so I'd like the final

Does Haskell have foldlM'?

心不动则不痛 提交于 2020-01-02 02:02:24
问题 How does one fold over a monad strictly? Data.Foldable has the strict foldl' and the monadic foldlM , but no strict foldlM' ? Is the strictness somehow defined by the monad itself? If so, how does one work out what it is? Imagine I must determine whether the product of an enormous list of ring elements is zero, but my ring isn't an integral domain, i.e. it contains zero devisors. In this case, I should tail recursively foldl my multiplication *** over the list, but return False the moment the