haskell

How to work with data structures in Haskell? [closed]

不问归期 提交于 2020-02-08 10:02:30
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 11 days ago . I'm assigned to make a simple program that contains a students array (which should contain students data), I know that Haskell is not an OO programming language, I was looking for a way for structuring my student data, I thought of nesting tuples into arrays and then into the

Parse errors when using partial functions in where statments (Haskell) [closed]

我与影子孤独终老i 提交于 2020-02-06 19:04:58
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . I'm pretty new to Haskell and I've run into this problem a few times and have had no luck finding answers online. playDomsHandler (dp1,h1,s1) (dp2,h2,s2) b _ -- players 1 and 2 both knocking, game ends | knockingP b h1 && knockingP b h2 = (b, (s1, s2)) -- just player 1 knocking, player 2 makes a move | knockingP

Standard combinator to get first “non-empty” value from a set of monadic actions

ⅰ亾dé卋堺 提交于 2020-02-05 02:34:07
问题 I'm sure I am missing something very obvious here. Here's what I'm trying to achieve at a conceptual level: action1 :: (MonadIO m) => m [a] action1 = pure [] action2 :: (MonadIO m) => m [a] action2 = pure [1, 2, 3] action3 :: (MonadIO m) => m [a] action3 = error "should not get evaluated" someCombinator [action1, action2, action3] == m [1, 2, 3] Does this hypothetical someCombinator exist? I have tried playing round with <|> and msum but couldn't get what I want. I guess, this could be

Can one express catamorphism through Data.Function.fix?

吃可爱长大的小学妹 提交于 2020-02-04 05:33:29
问题 I have this lovely fixana function here that performs about 5 times faster than her sister ana . (i have a criterion report to back me on this) ana alg = Fix . fmap (ana alg) . alg fixana alg = fix $ \f -> Fix . fmap f . alg Can I express their cousin cata in the same fashion? cata f = f . fmap (cata f) . unFix It seems to me that I cannot, but I have been humbled by my S.O. fellows quite a few times in the past. 回答1: Actually, this has nothing to do with catamorphisms. Whenever a function is

cabal install wx Missing C library

穿精又带淫゛_ 提交于 2020-02-03 08:56:12
问题 Env: OS: feodra 16 haskell-platform wxGTK-devel ghc 7.0.4 I am trying to install wxHaskell with cabal install wx Then these errors are given. Missing dependencies on foreign libraries: * Missing C libraries: wx_baseu-2.8, wx_baseu_net-2.8, wx_baseu_xml-2.8, wx_gtk2u_core-2.8, wx_gtk2u_adv-2.8, wx_gtk2u_html-2.8, wx_gtk2u_qa-2.8, wx_gtk2u_xrc-2.8, wx_gtk2u_aui-2.8, wx_gtk2u_richtext-2.8, wx_gtk2u_media-2.8, wx_gtk2u_stc-2.8, wx_gtk2u_gl-2.8 And these libraries actually exist in /usr/lib I type

cabal install wx Missing C library

老子叫甜甜 提交于 2020-02-03 08:53:12
问题 Env: OS: feodra 16 haskell-platform wxGTK-devel ghc 7.0.4 I am trying to install wxHaskell with cabal install wx Then these errors are given. Missing dependencies on foreign libraries: * Missing C libraries: wx_baseu-2.8, wx_baseu_net-2.8, wx_baseu_xml-2.8, wx_gtk2u_core-2.8, wx_gtk2u_adv-2.8, wx_gtk2u_html-2.8, wx_gtk2u_qa-2.8, wx_gtk2u_xrc-2.8, wx_gtk2u_aui-2.8, wx_gtk2u_richtext-2.8, wx_gtk2u_media-2.8, wx_gtk2u_stc-2.8, wx_gtk2u_gl-2.8 And these libraries actually exist in /usr/lib I type

Haskell: Could not find module `Data.List.Split'

非 Y 不嫁゛ 提交于 2020-02-03 05:16:41
问题 I'm trying to split a list in Haskell. As to my knowledge, the easiest way to do this is with splitOn , but this function requires Data.List.Split , so I tried to run import Data.List.Split in Prelude. However, I got the following error: Could not find module Data.List.Split Simply importing Data.List does work, however. What could I do to solve this? Or, even better: is there an easy, built-in alternative to split lists? 回答1: To split a String on arbitrary white space (e.g. any Char c where

Haskell Inaccessible code bug?

北战南征 提交于 2020-02-03 05:05:06
问题 Say I have the following (erroneous) code. data A a b where APure :: (A a b) AApply :: A (A b c) c test :: (A a b) -> a -> b test (APure) a = a test AApply a = undefined GHC will then give me this error: Couldn't match type `b' with `A b1 b' `b' is a rigid type variable bound by the type signature for test :: A a b -> a -> b Inaccessible code in a pattern with constructor AApply :: forall c b. A (A b c) c, in an equation for `test' In the pattern: AApply In an equation for `test': test AApply

Weird behavior of (^) in Haskell

拟墨画扇 提交于 2020-02-03 04:11:31
问题 Why does GHCi give incorrect answer below? GHCi λ> ((-20.24373193905347)^12)^2 - ((-20.24373193905347)^24) 4.503599627370496e15 Python3 >>> ((-20.24373193905347)**12)**2 - ((-20.24373193905347)**24) 0.0 UPDATE I would implement Haskell's (^) function as follows. powerXY :: Double -> Int -> Double powerXY x 0 = 1 powerXY x y | y < 0 = powerXY (1/x) (-y) | otherwise = let z = powerXY x (y `div` 2) in if odd y then z*z*x else z*z main = do let x = -20.24373193905347 print $ powerXY (powerXY x 12

Adding Haskell's Monadic Bind Operator to Scala

两盒软妹~` 提交于 2020-02-03 03:26:08
问题 In Haskell, you can use the bind operator ( >>= ) like this: repli :: [a] -> [a] repli xs = xs >>= \x -> [x,x] *Main> repli [1,2,3] [1,1,2,2,3,3] I've read that flatMap is Scala's bind operator: def repli [A](xs: List[A]): List[A] = xs.flatMap { x => List(x,x) } scala> repli (List(1,2,3)) res0: List[Int] = List(1, 1, 2, 2, 3, 3) As a pedagogic exercise, I'm trying to add support for >>= to Scala: class MyList[T](list: List[T]) { def >>= [U](f: T => List[U]): List[U] = list.flatMap(f) }