haskell

how to know in Haskell the builtins functions?

强颜欢笑 提交于 2019-12-24 11:44:53
问题 I look for a way to get all the builtins namespace of prelude Haskell. something equivalent to what we can have in Python doing this:: >>> print([func for func in dir(__builtins__) if func[0].islower()]) ['abs', 'all', 'any', 'ascii', 'bin', 'bool', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'exec', 'exit', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr

Does this Bool-producer to Maybe-producer function appear in any common library?

别说谁变了你拦得住时间么 提交于 2019-12-24 11:34:21
问题 I found myself wanting this tiny little function, but it doesn't seem to be in Data.Maybe . Is it somewhere else? splat :: (a -> Bool) -> a -> Maybe a splat c a | c a = Just a | otherwise = Nothing 回答1: The package monadplus contains exactly this function, named partial: partial :: (a -> Bool) -> a -> Maybe a 回答2: splat :: MonadPlus m => (a -> Bool) -> a -> m a splat c x = guard (c x) >> return x would be a shorter, more general definition, if you decided you want this. But just using guard

Can docker solve a problem of mismatched C shared libraries?

前提是你 提交于 2019-12-24 11:28:15
问题 I am trying to run some haskell code on an ubuntu (18.04) host, which was compiled on my laptop. host: 4.15.0-36-generic #39-Ubuntu SMP Mon Sep 24 16:19:09 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux laptop: 4.14.74-1-MANJARO #1 SMP PREEMPT Fri Oct 5 14:16:52 UTC 2018 x86_64 GNU/Linux The error I get is /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found After doing some research I learned that this is because my laptop has version 2.28 of glibc installed, but the host only has libc6

Why is there an unexpected “expected type” of () in this conduit composition (fusion)?

≡放荡痞女 提交于 2019-12-24 11:18:20
问题 I have the following conduit components that are being fused together: awaitVals () :: ConduitT (Element mono) (Element mono) m () intermTmp :: forall o. (Element mono -> Bool) -> ConduitT (Element mono) o m ([Element mono]) The fusion occurs like: awaitVals () .| intermTmp curPred . According to the fuse function ( .| ), I think the types should be OK here. Fuse is: (.|) :: Monad m => ConduitT a b m () -> ConduitT b c m r -> ConduitT a c m r Here's the entire function definition:

Haskell Scotty and Angularjs: jsonData function stopped parsing json data sent with $http.post()

安稳与你 提交于 2019-12-24 11:10:47
问题 I have a Haskell/Scotty app with Angularjs as frontend. It worked flawlessly with regards to JSON parsing. Then it suddenly stopped for no reason. It happend after some Scotty and its dependencies version bump. There is not much error feed back from the scotty jsonData function which parses JSON body. None of the POST requests from Angular work at the moment. I can't figure out what happened. I don't know which code example would be useful as any JSON POSTs result with jsonData - no parse

No instance for (Eq a0) arising from a use of ‘==’

烈酒焚心 提交于 2019-12-24 10:38:46
问题 I'm new to haskell and I'm trying to solve this haskell problem http://www.haskell.org/haskellwiki/99_questions/1_to_10#Problem_7 . To verify the result I created some tests using Test.QuickCheck module. import Test.QuickCheck import Test.QuickCheck.All {- ------------- -} {- SOLUTION -} {- ------------- -} data NestedList a = Elem a | List [NestedList a] flatten :: NestedList a -> [a] flatten (Elem x) = [x] flatten (List x) = concatMap flatten x {- ------------- -} {- TEST CASE -} {- -------

Compiler doesn't pick up typeclass for the polymorphic constant value

送分小仙女□ 提交于 2019-12-24 10:37:38
问题 I'm new to Haskell, so forgive me in advance. Why doesn't the following haskell code compile? It seems like the compiler somehow fails to see that the type of the expression (maxBound :: a) is a which has an Enum instance provided, not some type variable ‘a0’ which is ambiguous . class (Enum a, Bounded a) => SafeEnum a where ssucc :: a -> a ssucc x = if (fromEnum x) < (fromEnum (maxBound :: a)) then succ x else minBound spred :: a -> a spred x = if (fromEnum x) > (fromEnum (minBound :: a))

Sum the total balance for people between two ages

耗尽温柔 提交于 2019-12-24 10:29:11
问题 I'm trying to calculate the total balance of people/clients between two ages that have an account within a bank. I can get it to display the list of people that fall under the requirement. These are the constructors type NI = Int type Age = Int type Balance = Int type Person = (NI, Age, Balance) type Bank = [Person] This is the Bank rbs :: Bank rbs = [ (1, 73, 1000) , (2, 18, -50) , (3, 60, 190) , (4, 26, 300) , (5, 24, 456) , (6, 32, 7500) , (7, 41, -46) , (8, 59, -850) , (9, 44, 348) , (10,

How do I print special characters like tabulations or newlines?

[亡魂溺海] 提交于 2019-12-24 10:26:05
问题 [m@green09 ~]$ ghci GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Prelude> print "asdf" "asdf" Prelude> print "\tasdf" "\tasdf" Prelude> Awesome. Just awesome. How to print a tabulation or newline? 回答1: You just do it. > putStrLn "a\tb" a b 回答2: When you insert a value of type Show a => a into the REPL, the ghci will execute print on it,

How can I remove widgets from WxHaskell panel

心已入冬 提交于 2019-12-24 10:17:03
问题 My google-fu has failed me. How can I remove widgets that I've added to a Panel () ? For example, in the following, I want the controls -panel to become empty again. buildGUI = do f <- frame [ text := "Hello" ] controls <- panel f [] ctext <- staticText controls [ text := "Foo" ] set controls [ layout := margin 5 (widget ctext) ] set f [ layout := widget controls ] {- delete ctext ? How? -} return () (I'm trying to build a dynamic GUI, and I need to get rid of the old controls when it updates