haskell

What is Haskell's style of polymorphism?

依然范特西╮ 提交于 2019-12-29 18:37:03
问题 With Haskell's type classes it almost seems that it enables ad hoc polymorphism, but its functions declarations seem parametric polymorphism. Am I mixing my understanding of different things? 回答1: Indeed, Haskell supports both (higher rank) parametric polymorphism, and ad hoc (or bounded ) polymorphism. Parametric polymorphism in Haskell is supported via its Hindley-Milner/System F type system. Ad hoc polymorphism is supported via type classes. For the origin of type classes and ad hoc

Modular Program Design - Combining Monad Transformers in Monad Agnostic functions

落爺英雄遲暮 提交于 2019-12-29 14:54:26
问题 I am trying to come up with a modular program design and I, once again, kindly request your help. As a follow-up to these following posts Monad Transformers vs passing Parameters and Large Scale Design in Haskell, I am trying to build two independent modules that use Monad Transformers but expose Monad-agnostic functions, then combine a Monad-agnostic function from each of these modules into a new Monad-agnostic function. I have been unable to run the combining function e.g. how do I call

Modular Program Design - Combining Monad Transformers in Monad Agnostic functions

落花浮王杯 提交于 2019-12-29 14:52:09
问题 I am trying to come up with a modular program design and I, once again, kindly request your help. As a follow-up to these following posts Monad Transformers vs passing Parameters and Large Scale Design in Haskell, I am trying to build two independent modules that use Monad Transformers but expose Monad-agnostic functions, then combine a Monad-agnostic function from each of these modules into a new Monad-agnostic function. I have been unable to run the combining function e.g. how do I call

Algorithm to create fair / evenly matched teams based on player rankings

牧云@^-^@ 提交于 2019-12-29 14:33:02
问题 I have a data set of players' skill ranking, age and sex and would like to create evenly matched teams. Teams will have the same number of players (currently 8 teams of 12 players). Teams should have the same or similar male to female ratio. Teams should have similar age curve/distribution. I would like to try this in Haskell but the choice of coding language is the least important aspect of this problem. 回答1: This is a bin packing problem, or a multi-dimensional knapsack problem. Björn B.

Algorithm to create fair / evenly matched teams based on player rankings

我与影子孤独终老i 提交于 2019-12-29 14:30:32
问题 I have a data set of players' skill ranking, age and sex and would like to create evenly matched teams. Teams will have the same number of players (currently 8 teams of 12 players). Teams should have the same or similar male to female ratio. Teams should have similar age curve/distribution. I would like to try this in Haskell but the choice of coding language is the least important aspect of this problem. 回答1: This is a bin packing problem, or a multi-dimensional knapsack problem. Björn B.

Can a monad be a comonad?

天大地大妈咪最大 提交于 2019-12-29 11:49:09
问题 I know what a monad is. I think I have correctly wrapped my mind around what a comonad is. (Or rather, what one is seems simple enough; the tricky part is comprehending what's useful about this...) My question is: Can something be a monad and a comonad? I foresee two possible answers: Yes, this is common and widely useful. No, they do such different jobs that there would be no reason to want something to be both. So, which is it? 回答1: Yes. Turning some comments into an answer: newtype

Comparison of Priority Queue implementations in Haskell

こ雲淡風輕ζ 提交于 2019-12-29 10:12:12
问题 There seem to be several priority queue implementations available off-the-shelf for Haskell. For instance, there's: Data.PriorityQueue.FingerTree (in fingertree-0.0.1.0 on hackage) Data.PurePriorityQueue (in pure-priority-queue-0.14 on hackage) both of which appear to be pure priority queue data structures. The former is based on finger trees, a data structure with which I'm unfamiliar; the latter is a wrapper around Data.Map. There's also Data.Heap (in heap-1.0.0 on hackage) which defines

haskell sum type multiple declaration error

半世苍凉 提交于 2019-12-29 09:34:14
问题 data A=A data B=B data AB=A|B Which makes a sum type AB from A and B. but the last line induces a compile error "multiple declarations of B" I also tried sth like this: data A=Int|Bool It compiles. but why ghc disallows me from making sum types for user-defined types? 回答1: You're getting fooled. You think when you write data A=Int|Bool that you are saying that a value of type A can be a value of type Int or a value of type Bool ; but what you are actually saying is that there are two new

How to make lenses for records with type-families [duplicate]

旧巷老猫 提交于 2019-12-29 09:10:16
问题 This question already has answers here : How to derive instances for records with type-families (2 answers) Closed 2 years ago . Here's what I've got, which is not compiling: {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE FunctionalDependencies #-} import Data.Text as T import Data.Int (Int64) import Control.Lens type family Incoming validationResult

How to build matrix of zeros using hmatrix?

泪湿孤枕 提交于 2019-12-29 09:05:55
问题 Trying to use hmatrix, to create a zero marix. For some reason, when I try this on command line, it works: buildMatrix 2 3 (\(r,c) -> fromIntegral 0) However, when I try to do the same thing in my code: type Dim = (Int, Int) buildFull :: Matrix Double -> Vector Int -> Vector Int -> Dim -> Int buildFull matrix basic nonbasic (m, n) = do -- Build mxn matrix of zeroes let f = buildMatrix m n (\(r,c) -> fromIntegral 0) m it fails: Pivot.hs:23:17: Ambiguous type variable `a0' in the constraints: