Questions tagged [haskell]

28763 questions
1

votes
0

answer
84

Views

Haskell: Conversions of polymorphic types

I wanted to write a library that can convert types between various isomorphic formats and from 'subtypes' to 'supertypes', for example using the following isomorphisms and injections: (a, (b, c)) ((a, b), c) (Either a (Either b c)) (Either (Either a b) c) (a, ()) a ((), a) (Either a Void) a...
Benjamin Berger
1

votes
0

answer
54

Views

`createTree: already exists (File exists)` error when running `ghcjs-boot`

When running ghcjs-boot I get a whole bunch of: ignoring unexpected entry type in tar. only normal files and directories (no links) are supported: ghcjs-boot/./@LongLink Before finally: ghcjs-boot: /Users//.ghcjs/x86_64-darwin-0.2.1-8.0.2/ghcjs/ghcjs-boot/boot/aeson/tests/JSONTestSuite/parsers/test_...
semicolon
1

votes
0

answer
53

Views

Authentication for groups of users with different permissions in Servant

I would like to implement a permission system for my API wherein the endpoints available to admins are a superset of those available to superusers, which are a superset of those of regular users. What is an elegant way to do this in Servant? Should I use several AuthProtect combinators, each of whic...
nnnmmm
1

votes
0

answer
267

Views

Why can I load a module in GHCi, while Atom can't find it?

I'm using Haskell with Stack and Atom on Windows 10. Sometimes, I like to just write a stand-alone .hs file to play around with various things. When I do that, I prefer to interact with it using GHCi. Usually, I start it from Git Bash: $ stack ghci --color never From here, I can add modules: Prelude...
Mark Seemann
1

votes
0

answer
59

Views

Haskell - can't generate and use Image file in threepenny

I will try to be as specific as possible. I am trying to make a graph visualization GUI using Haskell, Threepenny and DOT I have created buttons that modify the graph, and I am trying to save the modified graph in the image and load that image Every Time the graph is modified However, I can run the...
Tim Bill
1

votes
0

answer
46

Views

How to add tarball (Cardinality package) to dependency with stack?

I have mylib library package and myapp application. I want to use Cardinality package in mylib which is available only as tarball. So, I added to mylib stack.yaml: packages: ... - location: https://hackage.haskell.org/package/Cardinality-0.2/Cardinality-0.2.tar.gz extra-dep: true Then I add to mylib...
Paul-AG
1

votes
1

answer
71

Views

How to dispatch different types from a ContT?

I want to create a generalized form of IO based on ContT. I created a GADT to represent different IO actions: data Cmd a where PutChar :: Char -> Cmd () GetChar :: Cmd Char I wrote a function that transforms these into IO commands for use in the IO monad like so: continueIO :: Cmd a -> IO a continue...
robbie0630
1

votes
0

answer
60

Views

Fill database table with data from config files on app startup

I want the initial database state in my yesod web app to be defined by config files that are parsed on app startup. My current approach to achieve this compiles, but doesn't seem to do anything, I suspect this is because the database may not be ready for use at that point or needs to be accessed dif...
Benjoyo
1

votes
0

answer
75

Views

How can you decompose/compose types using the Type.Reflection library?

This is related to a previous question of mine, where I was directed to the new functionality in GHC 8.2. The new (in base 4.10) Type.Reflection library claims: The interface provides TypeRep, a type representation which can be safely decomposed and composed. See Data.Dynamic for an example of this...
jkeuhlen
1

votes
0

answer
83

Views

How to generate random json diffs in haskell quickcheck

I need to test the framework that can observe the state of some json http resource (I'm simplifying a bit here) and can send information about its changes to message queue so that client of service based on this framework could reconstruct actual state without polling http resourse. It's easy to for...
user1685095
1

votes
0

answer
48

Views

Repetition of class constraints in instances

Why does the first instance declaration require an explicit mention of Num a where the second does not? Why can't Num be equally inferred by the class constraint of C1 in both cases? class Num a => C1 a b instance (Num a, C1 a Int) => C1 a Char class C1 a b => C2 a b instance C2 a Int => C2 a Char
Clinton
1

votes
0

answer
67

Views

State hack: why is eta-expanding State# lambdas important for performance?

GHC -O can cause severe pessimisation of some programs because of 'state hack'. Why the 'state hack' (i.e. eta-expanding State# lambdas) is so important for performance of others? References: Why does this Haskell code run slower with -O? https://ghc.haskell.org/trac/ghc/ticket/10102 https://ghc.has...
sevo
1

votes
1

answer
57

Views

Send list of IDs in Yesod route

I want to have a route in my Yesod app that accepts a list of IDs From this page it looks like you can use * in your route to accept a list but when I attempted it /api/user/#UserId UserR GET DELETE /api/users/display/*UserIds DisplayR GET I got the error Not in scope: type constructor or cl...
Qwertie
1

votes
0

answer
35

Views

Changing Heroku app command when directly pushing docker image

I'm building a docker image locally and pushing it directly to Heroku using docker tag registry.heroku.com// docker push registry.heroku.com// as explained here. The reason for doing it this way is to be able to use stack's docker integration, which seems promising. I set it up using the following...
jorgen
1

votes
1

answer
155

Views

Using ReaderT transformer in ScottyT (vs ActionT)

I'm trying to thread configuration through my Scotty based application using ReaderT monad transformer approach, and having trouble doing so. I have to use configuration both when defining routes (as some of them depend on the config) and when handling actual requests. The latter works just fine in...
SkyWriter
1

votes
0

answer
91

Views

Sequencing monadic actions where every action takes the original input

I'm currently experimenting with the JSaddle library in ghcjs. I don't have much of any experience with lenses yet. Somewhere in this library they seem to define a getter lens which is actually a sort of monadic setter: https://github.com/ghcjs/jsaddle/blob/3f8b32833917f1a2dfbdb81ef00992fb54733c9a/j...
rtytgat
1

votes
0

answer
260

Views

Third time's the charm - Nondeterministic Stack / GHC

I've been trying to install the package text using Stack inside an Ubuntu VM. The funny thing is - it doesn't the work the first time (Stack stops with a segfault), it doesn't work the second time (an internal GHC error) but it works the third time. The VM is set up using the following Vagrantfile....
theindigamer
1

votes
0

answer
63

Views

Why is IOUArray faster than StorableArray in Haskell/GHC?

Documentation of StorableArray says: It is similar to IOUArray but slower. Its advantage is that it's compatible with C. I have checked it in my code, that statement is really true. But I do not understand, why. I assume that StorableArray is plain data without boxing and access via poke and peek is...
Lemming
1

votes
1

answer
82

Views

how to convert SqlByteString to String [HDBC]

I want do something on mysql with hdbc , I want know how can I convert SqlByteString to String? when I try to use fromSql bytestrobj, I got an error :20:1: error: • Non type-variable argument in the constraint: Data.Convertible.Base.Convertible SqlValue a (Use FlexibleContexts to permit this) ...
Lee Lee Lee
1

votes
0

answer
64

Views

After defining the name of a type classes in Haskell, what does the vertical bar followed by a function mean? [duplicate]

This question already has an answer here: What's the “|” for in a Haskell class definition? 2 answers Functional dependencies in Haskell 3 answers I was taking a look at the megaparsec library and noticed that a class is defined as class (Stream s, A.Alternative m, MonadPlus m) => MonadParsec...
mtber75
1

votes
0

answer
83

Views

How to wrap conduit pipe into state?

I have a code that takes stream of json arrays from stdin and computes candlesticks from them. I've implemented function diff that should compute difference between old state and new state in State Monad, but I don't know how to use with conduit. The idea is that each json array is a batch of data....
user1685095
1

votes
0

answer
65

Views

Highest number of continuous zeros in Haskell

In Haskell, I have this: import Numeric import Data.Char import Data.List toBin :: Integer -> Integer toBin n = read (showIntAtBase 2 intToDigit n '') -- λ> toBin 558745840 -- 100001010011011100100011110000 -- (0.01 secs, 117,680 bytes) digits :: Integer -> [[Integer]] digits n = group [read[d] | d...
mathandtic
1

votes
1

answer
47

Views

How do I filter Just field in Esqueleto?

With the following Persistent schema, Picture bytes ByteString desc Text Maybe I want to query SELECT id, desc FROM picture WHERE desc IS NOT NULL. But previews :: SqlPersistT Handler [(E.Value (Key Picture), E.Value Text)] previews = E.select $ from $ \pics -> do where_ $ pics ?. PictureDesc E.!=....
jeiea
1

votes
0

answer
75

Views

Running with Packet Capture Permissions under Stack

Not sure if this is more appropriate for Server Fault so apologies if this is the case. I am currently trying to capture packets using the Network.Pcap library and have written this wrapper function around it: getRawPacket :: IO B.ByteString getRawPacket = do deviceName = (\(_,p) -> return p) I am u...
Josh Taylor
1

votes
1

answer
303

Views

GHC 8.2.2 won't import Data.Vector?

I've been using ghc 8.0.2 and I recently installed ghc 8.2.2. I tried compiling my project and got the following error message: Could not find module ‘Data.Vector’ Perhaps you meant Data.Functor (from base-4.10.1.0) Use -v to see a list of the files searched for. | 17 | import qualified Data.Vec...
Eben Cowley
1

votes
0

answer
43

Views

Happstack SSL error - wrong tag

I am trying to run happstack-tls server using certificate generated by certbot, however, when I run it I get user error (error:0D0680A8:asn1 encoding routines:asn1_check_tlen:wrong tag) and program ends. I tried to use both pem and der versions of certificate, but without success. Here is the code:...
radrow
1

votes
0

answer
69

Views

Equivalence verification using Lava

I've been trying to verify equivalence property between two circuits in Chalmers Lava. I have declared a type bit: type Bit = Signal Bool And I have two circuits each has a list of bits as input and a tuple of lists of bits, and a function that checks their equivalence: circuit1:: [Bit] ->([Bit],...
Balkis
1

votes
0

answer
84

Views

Negative Lookahead in a Monadic Parser

I have a monadic parser that I'm implementing as an exercise. Its signature looks like this: type Parser err src target = ExceptT err (State [src]) target I've already implemented many basic helpers, but I've come across a use case where a negative lookahead is necessary. In particular, I think I'd...
Bailey Parker
1

votes
0

answer
171

Views

What is the difference between empty and void type in Haskell

In Hask, Void (uninhabited type) is the initial object of the category: data Void The unique function is required to show that Void is indeed the initial object: absurd :: Void -> a absurd = absurd The type Void is not quite empty because Haskell types have bottom, but what is the difference between...
GoDev
1

votes
0

answer
84

Views

Define function independent of specific value constructor (templates?)

Is it possible to write a function for generic types (in this case applicatives) without making assumptions about the name of type constructors? I can write the following: f :: Maybe a -> Maybe a f (Just a) = (Just a) That one works on Maybes and only instances with the Just constructor. But say I h...
lo tolmencre
0

votes
0

answer
14

Views

How do I send and receive file descriptors over Unix sockets in Rust?

To send a file descriptor in Haskell it's fairly simple: I connect to a Unix domain socket and use the sendFd function with whatever file descriptor I want as a parameter (in my case stdin): sock
Ulrar
0

votes
0

answer
4

Views

No instance for FromYAML Text arising from a use of ‘decodeStrict’

I want to decode simple YAML content to Haskell using HsYAML. I am using the example in the Documentation of HsYAML but I can't figure out what is wrong my code. I installed the HsYAML library in the cabal sandbox and then I loaded my file in ghci. The code is given below: {-# LANGUAGE OverloadedStr...
vphoenix
1

votes
1

answer
39

Views

String Extract from PublicKey of Crypto.PubKey.Ed25519

This is my code, was trying in GHCI import Crypto.PubKey.Ed25519 import Crypto.Error import Data.ByteString.Char8 str :: String;str = 'hellohellohellohelloǰello%$*/.õƲ' getSecretKey seedString = throwCryptoError (secretKey (pack seedString)) getPublicKey secretKey = toPublic secretKey sk = getSec...
Mahesh Uligade
1

votes
1

answer
80

Views

Simple prime number challenge haskell code gives incorrect answer

the code below tries to solve https://projecteuler.net/problem=87 import Math.NumberTheory.Primes.Sieve -- from package arithmoi gen::[Integer]->Integer->[Integer]-- time complexity : n! , n = numberofprimes gen pmlist limit=filter (\x->x(x^2)
doofin
1

votes
0

answer
109

Views

Haskell State Management [duplicate]

This question already has an answer here: How do I avoid referring to all state variables when updating only a few? 3 answers Simulating interacting stateful objects in Haskell 3 answers Imagine in a game, I have to manage the states of several entities. A typical way of managing one state is to:...
McBear Holden
1

votes
0

answer
53

Views

Mockable Functionalities by Mixing Monad Transformers

How can I build separate functionalities in independent and mockable monads and then put them together in my main app monad? For example let's assume my app has a chat feature. I am following Unit testing effectful Haskell with monad-mock and I should be able to easily switch the implementation of a...
homam
1

votes
1

answer
38

Views

In Opaleye, how to insert to two tables in the same query?

My database has two tables with bijective row correspondence (as described in this question). It seems this means that to insert a row to each table without violating foreign key constraints requires the two inserts to occur within the same query. In the Opaleye.Manipulation module I see functions s...
mherzl
1

votes
0

answer
250

Views

How to configure Spacemacs to use the global installed intero?

Whenever I create a new project and I open it with Spacemacs, Spacemacs will try to install a local intero over and over again leaving me waiting for it to finish the installation. Can I just use my global installed intero for all my stack projects?
Vimniky Luo
1

votes
1

answer
72

Views

Adapting Store decoding for streaming library

I am trying to adapt Store encoding and decoding for Streaming. Store already implements a streaming decode with a function called decodeMessageBS. I tried to do a basic implementation of store deserialization for Streaming as below (without bracket for now to keep it simple). However, there seems...
Sal
1

votes
0

answer
181

Views

Typeclass like `IsList` without the `fromList` function

The GHC.Exts module exports the IsList typeclass: class IsList l where type Item l fromList :: [Item l] -> l toList :: l -> [Item l] fromListN :: Int -> [Item l] -> l fromListN _ = fromList I have a data-type defined as follows: newtype MyData = MyData { toMap :: Map (RefTo X) X } Somtimes it...
Damian Nadales

View additional questions