haskell

Stack ExitFailure 1

被刻印的时光 ゝ 提交于 2020-03-28 06:40:48
问题 I've been trying to run stack install hsdev --stack-yaml ./Documents/hsdev.yaml , where hsdev.yaml contains packages: [] resolver: lts-13.29 extra-deps: - hsdev-0.3.3.4 - hdocs-0.5.3.2 - haddock-api-2.22.0 - network-3.0.1.1 This returns the error -- While building package haddock-api-2.22.0 using: /home/hello/.stack/setup-exe-cache/x86_64-linux/Cabal-simple_mPHDZzAJ_2.4.0.1_ghc-8.6.5 --builddir=.stack-work/dist/x86_64-linux/Cabal-2.4.0.1 build --ghc-options " -fdiagnostics-color=always"

Flexible serialization with MultiParamTypeClasses

拜拜、爱过 提交于 2020-03-26 05:55:22
问题 I'm playing around with an idea for an extensible serialization library. I have the following typeclass: class Monoid m => BuilderS m a where cstr :: String -> a -> m The idea is that people can define instances for pairs of different serializers/types, like this: import qualified Data.Serialize.Builder as B instance Serialize a => BuilderS B.Builder a where cstr _ = B.fromByteString . encode And a usage example: sfPut :: (BuilderS a b, Monoid a) => WriterT a Identity () sfPut = do tell $

How to modify fields of a nested custom data type with lenses, when modifications depend on indices

人走茶凉 提交于 2020-03-25 21:54:08
问题 Considering the following : {-# LANGUAGE TemplateHaskell #-} import Control.Lens data Typex = Typex { _level :: Int , _coordinate :: (Int, Int) , _connections :: [(Int,(Int,Int))] } deriving Show makeLenses ''Typex initTypexLevel :: Int -> Int -> Int -> [Typex] initTypexLevel a b c = [ Typex a (x, y) [(0,(0,0))] | x <- [0..b], y <- [0..c] ] buildNestedTypexs :: [(Int, Int)] -> [[Typex]] buildNestedTypexs pts = setConnections [ initTypexLevel i y y | (i,(_,y)) <- zip [0..] pts ] setConnections

How to modify fields of a nested custom data type with lenses, when modifications depend on indices

瘦欲@ 提交于 2020-03-25 21:54:08
问题 Considering the following : {-# LANGUAGE TemplateHaskell #-} import Control.Lens data Typex = Typex { _level :: Int , _coordinate :: (Int, Int) , _connections :: [(Int,(Int,Int))] } deriving Show makeLenses ''Typex initTypexLevel :: Int -> Int -> Int -> [Typex] initTypexLevel a b c = [ Typex a (x, y) [(0,(0,0))] | x <- [0..b], y <- [0..c] ] buildNestedTypexs :: [(Int, Int)] -> [[Typex]] buildNestedTypexs pts = setConnections [ initTypexLevel i y y | (i,(_,y)) <- zip [0..] pts ] setConnections

Interpreters for two polymorphic classes in one function

允我心安 提交于 2020-03-25 18:21:24
问题 I have this polymorphic code (see this question) with generic monads for model and client: import Control.Monad.Writer class Monad m => Model m where act :: Client c => String -> c a -> m a class Monad c => Client c where addServer :: String -> c () scenario1 :: forall c m. (Client c, Model m) => m () scenario1 = do act "Alice" $ addServer @c "https://example.com" and this is the pretty-print interpreter for the Client that explains the actions in the log via Writer monad: type Printer =

Interpreters for two polymorphic classes in one function

百般思念 提交于 2020-03-25 18:21:13
问题 I have this polymorphic code (see this question) with generic monads for model and client: import Control.Monad.Writer class Monad m => Model m where act :: Client c => String -> c a -> m a class Monad c => Client c where addServer :: String -> c () scenario1 :: forall c m. (Client c, Model m) => m () scenario1 = do act "Alice" $ addServer @c "https://example.com" and this is the pretty-print interpreter for the Client that explains the actions in the log via Writer monad: type Printer =

How to select a value in a range with QuickCheck?

▼魔方 西西 提交于 2020-03-22 09:47:08
问题 I have the following code I am using for creating a challenge on the following site : codewars describe "Random cases" $ do it "It should handle random test cases" $ property $ prop_check where prop_check (Positive x) = solution x == ref_sol x --- ref_sol function I would like to set the value of x in prop_check to be a positive int greater than 4 and at max a five-digit number (no more than five digits, i.e : max value = 99999). How would I go about approaching it ? 回答1: You can use

How monadicIO works

痞子三分冷 提交于 2020-03-22 09:03:11
问题 I have the following code fastShuffle :: [a] -> IO [a] fastShuffle a = <some code> prop_fastShuffle_correct :: [Int] -> Property prop_fastShuffle_correct s = monadicIO ( do sh <- run (fastShuffle s) return ( True ==> ( insertionSort sh == insertionSort s && if length s > 10 then s /= sh else True ) ) ) And .. it is working. I can't understand how what looks to be a pure function ( prop_fastShuffle_correct ) can call a non pure function that has side effects ( fastShuffle ). Hope that someone

Haskell: Splitting list into tuple of two new lists

心已入冬 提交于 2020-03-21 19:14:28
问题 I am having difficulty figuring out how to split a list of Ints into a tuple containing two new lists, such that every element (starting with first) goes into the first list and every other element in the second. Like so: split [] = ([],[]) split [1] = ([1],[]) split [1,2] = ([1],[2]) split [1,2,3] = ([1,3],[2]) split [1,2,3,4] = ([1,3],[2,4]) I'm trying to accomplish this recursively(with guards) and only using the single argument xs This is my approach that keeps getting error messages:

Are all fixed size containers strong monoidal functors, and/or vice versa?

北城余情 提交于 2020-03-21 11:38:05
问题 The Applicative typeclass represents lax monoidal functors that preserve the cartesian monoidal structure on the category of typed functions. In other words, given the canonical isomorphisms witnessing that (,) forms a monoidal structure: -- Implementations left to the motivated reader assoc_fwd :: ((a, b), c) -> (a, (b, c)) assoc_bwd :: (a, (b, c)) -> ((a, b), c) lunit_fwd :: ((), a) -> a lunit_bwd :: a -> ((), a) runit_fwd :: (a, ()) -> a runit_bwd :: a -> (a, ()) The typeclass and its laws