haskell

Haskell - How to transform map sum (map (x:) xss) to map (x+) (map sum xss)

ⅰ亾dé卋堺 提交于 2020-02-21 12:05:08
问题 Reading "Thinking Functionally with Haskell" I came across a part of a program calculation that required that map sum (map (x:) xss) be rewritten as map (x+) (map sum xss) Intuitively I know that it makes sense ... if you have some lists that you are going to sum but, before summing, to those same lists you are also going to add one element 'x', then that is the same as taking a list of sums of the origninal lists and adding x's value to each of them. But I would like to know how to transform

Why is the COPY instruction causing a cache miss in my Docker build

試著忘記壹切 提交于 2020-02-21 07:04:32
问题 The copy instruction in the docker file for my project seems to cause a cache miss, even though none of the files being copied have changed since the image was last pushed to docker hub. This causes all subsequent layers to miss the cache which makes the build take much longer than it should. I've also noticed that the hashes belonging to each layer seem to be different than what they are when I docker build on my local machine. Could this be because of a docker version mismatch? What is

Why is the COPY instruction causing a cache miss in my Docker build

拜拜、爱过 提交于 2020-02-21 07:03:35
问题 The copy instruction in the docker file for my project seems to cause a cache miss, even though none of the files being copied have changed since the image was last pushed to docker hub. This causes all subsequent layers to miss the cache which makes the build take much longer than it should. I've also noticed that the hashes belonging to each layer seem to be different than what they are when I docker build on my local machine. Could this be because of a docker version mismatch? What is

Converting Monad notation to Arrow notation

戏子无情 提交于 2020-02-17 13:35:36
问题 I'm trying to understand arrow notation, in particularly how it works with Monads. With Monads I can define the following: f = (*2) g = Just 5 >>= (return . f) and g is Just 10 How do I do the above but using arrow notation? 回答1: Changing your Monad thinking to Arrow thinking The first step to translating into Arrow is to move from thinking about m b on its own to thinking about a -> m b . With a monad, you'd write use x = do ..... .... doThis = do .... ... thing = doThis >>= use whereas an

Converting Monad notation to Arrow notation

北城以北 提交于 2020-02-17 13:32:43
问题 I'm trying to understand arrow notation, in particularly how it works with Monads. With Monads I can define the following: f = (*2) g = Just 5 >>= (return . f) and g is Just 10 How do I do the above but using arrow notation? 回答1: Changing your Monad thinking to Arrow thinking The first step to translating into Arrow is to move from thinking about m b on its own to thinking about a -> m b . With a monad, you'd write use x = do ..... .... doThis = do .... ... thing = doThis >>= use whereas an

How to reduce code duplication when dealing with recursive sum types

好久不见. 提交于 2020-02-17 05:16:34
问题 I am currently working on a simple interpreter for a programming language and I have a data type like this: data Expr = Variable String | Number Int | Add [Expr] | Sub Expr Expr And I have many functions that do simple things like: -- Substitute a value for a variable substituteName :: String -> Int -> Expr -> Expr substituteName name newValue = go where go (Variable x) | x == name = Number newValue go (Add xs) = Add $ map go xs go (Sub x y) = Sub (go x) (go y) go other = other -- Replace

How to reduce code duplication when dealing with recursive sum types

百般思念 提交于 2020-02-17 05:15:07
问题 I am currently working on a simple interpreter for a programming language and I have a data type like this: data Expr = Variable String | Number Int | Add [Expr] | Sub Expr Expr And I have many functions that do simple things like: -- Substitute a value for a variable substituteName :: String -> Int -> Expr -> Expr substituteName name newValue = go where go (Variable x) | x == name = Number newValue go (Add xs) = Add $ map go xs go (Sub x y) = Sub (go x) (go y) go other = other -- Replace

Why can't i re-use same value constructor among different data types?

有些话、适合烂在心里 提交于 2020-02-15 07:37:38
问题 i am new to Haskell and probably missing something really basic here, but i am not able to re-use same value constructor among different data types. data Colour = Red | Pink | Orange | Yellow data Fruit = Apple | Orange | Banana This produces error saying Multiple declarations of ‘Orange’ Not sure why this isn't allowed, i have been using OCaml before learning Haskell and was able to define types like this 回答1: As a quick exercise try just defining one of your data types and then opening up

Why can't i re-use same value constructor among different data types?

蹲街弑〆低调 提交于 2020-02-15 07:37:13
问题 i am new to Haskell and probably missing something really basic here, but i am not able to re-use same value constructor among different data types. data Colour = Red | Pink | Orange | Yellow data Fruit = Apple | Orange | Banana This produces error saying Multiple declarations of ‘Orange’ Not sure why this isn't allowed, i have been using OCaml before learning Haskell and was able to define types like this 回答1: As a quick exercise try just defining one of your data types and then opening up

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

回眸只為那壹抹淺笑 提交于 2020-02-08 10:05:43
问题 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