How to represent this type in Haskell

How can i represent a list which include 1 String and another list with maximum of 3 Strings. Like this one: osztaly = [("András", ["mákos", "meggyes", "almás"]), ("Joli", ["túrós"]), ("Anna", ["almás", "almás"]), ("Tamás", []), ("Mari", ["...
more »

2017-03-21 20:03 (1) Answers

What is wrong in this Haskell function?

I decided to dive in functional programming world recently, and a friend told me about Haskell. I started my own researches on the language particularity and soon I got the main concepts. Then, I started working with lists and decided to rewrite some...
more »

2017-03-21 20:03 (1) Answers

Haskell: deriving Show for Fix types

I'm trying to implement a recursive datatype using recursion-schemes. I would like to be able to print it. import Data.Functor.Foldable data T1F a = Foo deriving Show type T1 = Fix T1F data T2 = Bar T1 deriving Show -- error here Error message: ...
more »

2017-03-21 19:03 (1) Answers

Haskell and General Types

I'm kind of new to Haskell, and I would like to understand how general types works. What should be a "systematic" way of thinking to get the type of an expression? To make an example, if we have: (\x y z -> x (y z)) The way I would think abo...
more »

2017-03-21 14:03 (2) Answers

Recursive liftIO

I've looked at the some instances of MonadTrans, for MaybeT the implementation looks like this: instance MonadTrans MaybeT where lift = MaybeT . liftM Just As I understand the instance for MonadIO is used to do a variable number of lifts from ...
more »

2017-03-21 12:03 (2) Answers

Adding two lists together with map

So I'm trying to write some minimal code to put two lists of strings together, and to do this I thought it was best to use the haskell map function. Essentially I want to be able to do adders ["1","2"] ["3","4"] = ["1","2","3","4"] So I have a fun...
more »

2017-03-21 11:03 (1) Answers

Haskell Stack ghci flags

Basically, I am trying to achieve the following: stack ghci --flag proj:dev but it seems that flag is not valid for ghci, only for build. How can I achieve this? If possible *Notes: proj is a cloned yesod-postgres template, I do not want to use...
more »

2017-03-21 09:03 (0) Answers

Reduction stack overflow with static size list

I have following code implementing static sized vectors implemented as lists which compiles fine: {-# OPTIONS_GHC -fplugin GHC.TypeLits.Normalise #-} {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE DataKinds #-} ...
more »

2017-03-21 07:03 (1) Answers

Type Declaration For List of Num

I'm new to Haskell and I have no idea what I'm doing wrong here. The following code generates an error. numOfPos :: Num a => [a] -> Int numOfPos xs = length [x | x <- xs, x > 0] The code just returns the number of positive elements in ...
more »

2017-03-20 23:03 (1) Answers

Realgcc: no disk on D: error

Just installed the last version of the Haskell platform, but when calling "ghci" from CMD, I get the following error: Searched over the web for solutions, but the best I found was this post, which solution was reinstalling Windows. I do not want t...
more »

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

Functions Using Double List in Haskell

I am trying to learn Haskell, and I cannot find a solution to the following problem. Consider the following function with type ourFunction :: [[String]] -> [[String]]. When two adjoint strings are the same, they should change to 'x'. Example: ...
more »

2017-03-20 15:03 (2) Answers

Nested List Haskell Iteration

I need to implement a nested list operation in Haskell. f :: [[String]] -> [[String]] My input is a 2d array [ [ ”A” , ”A” , ”A” ] , [ ”B” , ”B” , ”A” ] , [ ”A” , ”A” , ”B” ] ] I arbitrarily generated th...
more »

2017-03-20 14:03 (1) Answers

Functor supertype has conflicting instances

I have defined a Fine-Grained Functor class (FgFunctor) in order to apply a constraint to the type of functions that may map over my Ordered Triple datatype (OrdTriple), which requires the contained type be orderable. import Data.List (sort) -- 'fi...
more »

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

Which Algebraic Pattern fits this type of tree?

I've got a puzzle for you, I managed to write some code that would do these things using recursion-schemes, but it's incredibly messy and that usually means that I missed a useful abstraction somewhere. I'm designing a layout system for my text edi...
more »

2017-03-19 20:03 (2) Answers

How can I install hsqml with Windows 10

When I install hsqml, I get the following error: cabal install hsqml Resolving dependencies... Configuring hsqml- Failed to install hsqml- Build log ( C:\Users\wjsgm\AppData\Roaming\cabal\logs\hsqml- ): cabal: Entering d...
more »

2017-03-19 17:03 (0) Answers

Haskell confuses Int with Int -> Int

I recently came across this weird issue in Haskell. The following code is supposed to return a value trimmed down to a range (if it's above high it should return high if it's under low it should return low. inRange :: Int -> Int -> Int -> I...
more »

2017-03-19 16:03 (1) Answers

Shuffling a List Based On an Int List

Given the code: data Error a = Fail|Ok a deriving (Eq, Ord, Show) split :: Int -> [a] -> (Error ([a],[a])) split 0 list = Ok ([], list) split n list | n < 0 = Fail | n > length (list) = Fail | otherwise = Ok (...
more »

2017-03-19 16:03 (2) Answers

JSON nested serialisation

Assume there is a data type data V = V { a :: Int, x :: Int, y :: Int } It has a correspondent JSON view E.g. V { a = 1, x = 2, y = 3 } need to be serialised like { "a": 1, "nested": { "x": 2, "y": 3 } } What ToJSON instance woul...
more »

2017-03-19 15:03 (1) Answers

Ambiguous occurrence `Monad'

I am currently working with Monad type classes, and here is my code: class Monad m where return :: a -> m a (>>==) :: m a -> (a -> m b) -> m b (>>) :: m a -> m b -> m b x >> y = x >>...
more »

2017-03-19 13:03 (0) Answers

Haskell - Scrape Amazon

I want to scrape Amazon using a program that takes a search term as the argument and outputs the name of the item and its price for the first 10 results. What would be the most efficient way to do this? I am not very familiar with functional progra...
more »

2017-03-19 11:03 (0) Answers

Haskell read function overloading with two inputs

In my haskell program I have a list that represents a database in [(key, value)] format. For example this is a valid database: [("key1", "value1"), ("key2", "value2"), ("key3", "value3")]. The key and value data will always have String type. My ques...
more »

2017-03-18 21:03 (2) Answers

Reading integers from a list

I'm facing the following problem in Haskell: I want to parse such list: ["1", "2", "3"] into a Maybe [Int]. What I can do is, using readMaybe from Text.Read, is get a [Maybe Int] int the following way: parseList :: [String] -> [Maybe Int] parseL...
more »

2017-03-18 19:03 (1) Answers