How to proof the number of possible functions?

Looking at function declaration, for example: myFoo :: Bool -> Bool I could say, the function myFoo has four possible unique implementation because function type is the exponent operator, here is the proof from the case above 2^2 = 4: myFoo1 :...
more »

2017-06-18 20:06 (3) Answers

Defining fmap for data type

So I've got those data types : data Stuff a = Stuff (StuffPart a) (StuffPart a) deriving (Show,Eq) data StuffPart a = Add a (StuffPart a)| End deriving (Show,Eq) , now is it possible to write a fmap function for Stuff ? Something like : instance ...
more »

2017-06-18 16:06 (2) Answers

Haskell parallel search with early abort

I'd like to search through a list, testing each element for property X and then return when an element with property X is found. This list is very large and would benefit from parallelism, but the cost of the spark is rather high relative to the com...
more »

2017-06-18 15:06 (1) Answers

Disallow assignment of values

I'm experimenting with a type-level permission system, and I'm trying to disallow assignment of values which do not originate from the same "source", i.e: data A = A { a :: Value, b :: Value } modify :: A -> A modify (A v) = A $ v { a = v.a } --...
more »

2017-06-18 15:06 (1) Answers

Comparing matrix shapes in accelerate-haskell

*Lib Lib A I> import Data.Array.Accelerate.Interpreter as I *Lib Lib A I> import Data.Array.Accelerate as A *Lib Lib A I> a = shape arr :: Exp DIM1 *Lib Lib A I> a' = unlift a :: (Z:. Exp Int) *Lib Lib A I> b = shape arr2 :: Exp DIM1 *...
more »

2017-06-18 15:06 (0) Answers

APIs for exploring Haskell source

I need an API (or set of APIs) that can: provide a listing of all packages in hackage given a package name, provide a listing of all modules in that package given a module name, provide a list of all functions and types exported from that module g...
more »

2017-06-18 04:06 (1) Answers

Parse error with Happy and attributed grammar

I'm a newbie of Haskell and Happy and I'm trying to make a parser with an attributed grammar in Haskell with Happy. I've made a little grammar just for variable declarations, given to BNFC and everything since here works fine. Then I start to add the...
more »

2017-06-17 16:06 (0) Answers

Dynamic parent element

I have this piece of code and it works perfectly fine. It toggles some styles on the text input field depending on the field value. numberInput :: (MonadWidget t m) => m (Dynamic t (Maybe Double)) numberInput = divClass "form-group" $ do let er...
more »

2017-06-17 12:06 (1) Answers

Construct a type

I have many type declarations: module SumProduct where data GuessWhat = Chickenbutt deriving (Eq, Show) data Id a = MkId a deriving (Eq, Show) data Product a b = Product a b deriving (Eq, Show) data Sum a b = First a | S...
more »

2017-06-16 16:06 (1) Answers

Resolving Stack Linker Error

What's the meaning of this stack output error? $stack build -v ... 2017-06-16 07:59:19.792336: [info] Linking .stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/my-project/my-project ... @(Stack/Build/Execute.hs:1070:67) 2017-06-16 07:59:22.457898: [w...
more »

2017-06-16 14:06 (1) Answers

Custom ToJSON instance for Persistent Key

I am building a web application in Haskell. I am using the persistent library to connect to a postgresql database. I am using the standard schema definition file system where template Haskell is used to generate types from the schema. share [mkPers...
more »

2017-06-16 13:06 (0) Answers

Haskell: Reading from file to a variable

I have the following code in Haskell: import System.IO data Plaster = Plaster [String] deriving (Read, Show) main = do putStrLn "Please choose path:" path <- getLine openn <- openFile path ReadMode plaster1 <...
more »

2017-06-16 13:06 (1) Answers

What is the value of the type?

I have following type declaration: data MyType = MyVal Int deriving (Eq, Show) As you can see, it has only one data type constructor with an argument. In the book, it says: Because MyVal has one Int argument, a value of type MyType must ...
more »

2017-06-16 09:06 (2) Answers

Haskell MArray performance benchmark

Haskell's MArray is supposed to provide a mutable array. I wonder how does it compare with a normal mutable array in an imperative programming language like Java or C. Is there any performance benchmark or feature comparison? ...
more »

2017-06-16 01:06 (0) Answers

Basic operations for linked lists in Haskell

I am trying to write some basic list operations for a linked list in Haskell but I could use a hand with this one. I want to append a list to another but it doesn't work at all, here is my code: data ML a = E | L a (ML a) deriving (Show) myList = (...
more »

2017-06-15 20:06 (1) Answers

Creating a Monad Transformer from a Monad

Given an arbitrary monad, is there a way to create a monad transformer based on that monad? I googled this question and didn't see anywhere where it was addressed (although I may have missed it) so I just tried to do it myself, and I got close, I thi...
more »

2017-06-15 17:06 (0) Answers

Creating Generic Typeclasses in Haskell

As an exercise to wrap my brain around Haskell types and typeclasses, I'm attempting to implement a simple DDD/CQRS style solution. I'm modelling it directly after Lev Gorodinski's F# Simple CQRS implementation. I've implemented a very simple Veh...
more »

2017-06-15 16:06 (2) Answers