Skip to main content
Filter by
Sorted by
Tagged with
0 votes
1 answer
38 views

is something wrong with my compiler or my syntax inn

im new to haskell and when i tried some basic syntax it seems to not work the way it is supposed to work. ive tried a couple of things but nothing seems to be working properly. im starting to assume ...
Computer noob's user avatar
1 vote
1 answer
40 views

Handle Error in refutable pattern when pattern matching in do notation

Suppose I have a function func :: a -> m (Maybe b), where m is a monad. Then, in a do for m, I can write example :: a -> m (Maybe b) example a = do Just x <- func a ..... If func a = ...
IsAdisplayName's user avatar
0 votes
3 answers
71 views

How do I use the "Maybe" data type in a math expression in Haskell?

MRE: foo :: (Eq a) => a -> [a] -> Maybe Int foo _ [] = Nothing foo n (m:ms) | -- some conditional statements that return Just <number here> | otherwise = 3 + (foo n ms) Error: ...
kesarling's user avatar
  • 2,112
4 votes
0 answers
53 views

type family instance for field types in servant's NamedRoutes

I'm looking for a way to decorate a servant API definition: Whenever an endpoint returns a list of things, I'd like to add a query parameter. So far, I have a type family that works on APIs that are ...
l7r7's user avatar
  • 1,328
4 votes
4 answers
153 views

Trying to understand Data.Text all function

I was playing around with the Data.Text all function, doing some trivial examples and combining them when I found that the evaluation of this trivial piece of code in GHCI is evaluating to True, the ...
Cloxure's user avatar
  • 1,841
5 votes
1 answer
74 views

Why no Fractional instance for Sum

In ghci: Data.Semigroup> 0.1 :: Sum Double <interactive>:2:1: error: [GHC-39999] • No instance for ‘Fractional (Sum Double)’ arising from the literal ‘0.1’ • In the expression:...
Daniel Wagner's user avatar
-4 votes
0 answers
74 views

I would like to make a gradebook for haskell(codewars), to improve my skills [closed]

I have tried to code at the codewars. I had a quest 8kyu of a gradebook I had tried to read the input and with else-if statement, let show the right score. X y z are the tree scores from which I have ...
Mr Kostja's user avatar
1 vote
1 answer
157 views

Servant client pagination

Given the following Servant API definition: type API = "single-content" :> Get '[JSON] Int :<|> "contents" :> QueryParam "page" Int :> Get '[JSON] (...
l7r7's user avatar
  • 1,328
0 votes
0 answers
30 views

vscode haskell extension error message "openTempFile: invalid argument (Invalid argument)compiler"

I am new to Haskell and when I code Haskell on vscode, an error message says "openTempFile: invalid argument (Invalid argument)compiler". Even though there is no syntax error and I can load ...
yzrtt22's user avatar
  • 37
1 vote
1 answer
94 views

Is there any concrete reason to prefer `Node a (Tree a) (Tree a)` over `Node (Tree a) a (Tree a)`? [closed]

Consider the following two binary tree definitions: data Tree a = Empty | Node a (Tree a) (Tree a) data Tree a = Empty | Node (Tree a) a (Tree a) I know this is a bit of a trivial question, but I am ...
lanf's user avatar
  • 357
1 vote
1 answer
77 views

How GHC captures the enviroment of variables when lambda expressions are used by value or by reference?

In this stackoverflow post there is code in C++ that tries to mimic associated types. When the lambda functions capture the environment(closure) using by reference capture the code compiles but fails ...
Dragno's user avatar
  • 3,125
1 vote
2 answers
91 views

Reading and writing files in Haskell results in "withFile: resource busy (file is locked)"

I am attempting to make a to-do list cli, and the program can save these tasks to a .txt file entitled tasks.txt, however, when I attempt to add new tasks or view the contents of the .txt file, it ...
elopez259's user avatar
1 vote
0 answers
54 views

Gstreamer linking videomixer request pads not working

I'm trying to link the sink request pad from videomixer to a videobox element like in here How to program videomixer using Gstreamer C API . But I'm getting a strange error stack exec gtk-intro-twelve-...
Ciuppo's user avatar
  • 43
1 vote
1 answer
64 views

How to get two videos playing in the same window using Gstreamer?

I am trying to get two videos playing in the same window using videomixer in Gstreamer. I read here https://gstreamer.freedesktop.org/documentation/videomixer/index.html?gi-language=c that it is ...
Ciuppo's user avatar
  • 43
5 votes
1 answer
134 views

Using a type variable at the term level

Consider the following GADT, Pin: {-# LANGUAGE GADTs, KindSignatures, DataKinds #-} module Mcu where import Data.Kind (Type) import GHC.Num.Natural (Natural) data Pin :: Natural -> Type where ...
jfMR's user avatar
  • 24.5k
5 votes
1 answer
191 views

Simple recursive sum when compiled from Haskell to WASM is quadratic

The following Haskell funcion: {-# LANGUAGE ForeignFunctionInterface #-} module Main where import Data.Word (Word32) sum' :: Word32 -> Word32 sum' 0 = 0 sum' n = n + sum' (n-1) foreign export ...
MaiaVictor's user avatar
  • 52.6k
5 votes
1 answer
89 views

`getLabel` or `fromLabel`

The GHC documentation for OverloadedLabels here shows examples like Leading capital letters: #Foo equivalant to getLabel @”Foo” Should getLabel be fromLabel? AFAIK getLabel is for creating unnamed ...
pat's user avatar
  • 12.7k
0 votes
1 answer
52 views

How to fix missing dependencies after deleting GHC's snapshots?

My C: drive was full, so I decided to remove all Haskell snapshots older than two month, knowing it could cause trouble. And it did : ghc-9.8.2.exe: addLibrarySearchPath: \\?\C:\sr\snapshots\d22c45cb\...
141592653's user avatar
  • 689
3 votes
1 answer
97 views

What is the current way (2024) to install and let run the Yi (Haskell) text editor?

Yi project seems asleep since 2017. On https://github.com/yi-editor/yi, [not so] recent problem reports remain unanswered. During that time ghc tools and hackage content keep evolve. Latest questions ...
fbpr4ups's user avatar
2 votes
1 answer
94 views

Is it possible to create custom Haskell "toplevels"?

I am writing a compiler in Haskell, trying to shun the lexing and parsing phases. I would like the source code to be an AST implemented as an algebraic type. My current structure is the following : I ...
Laurent LA RIZZA's user avatar
1 vote
1 answer
91 views

Parsing a large Json array in Haskell and strictly converting its elements

I have a json file containing (among other things) a large nested array of multiprecision floating point numbers. Each floating point number is a quoted string of digits, e.g. "3....
davidsd's user avatar
  • 781
2 votes
0 answers
62 views

Dynamic tables at runtime in Haskell Persistent

I'm trying to work out if there is a way one can have a have a runtime flag, that is able to dictate the shape of the schema. Let's say my runtime flag is Config, as you can see in my hypothetical ...
cmdv's user avatar
  • 1,753
4 votes
2 answers
188 views

How to understand the <- in Haskell's do notation with an uncommon ">>=" implementation in a Monad?

I am a C++/Rust programmer, and out of curiosity, I am currently learning Haskell. As expected, I encountered some obstacles while trying to understand Monads: I have already read about the definition ...
feipiao's user avatar
  • 59
4 votes
1 answer
72 views

TVar that blocks read until change?

I'm trying to wrap my head around how to correctly communicate between threads in Haskell. I have multiple threads that read some state, and whenever it changes they need to do some update. Then I ...
The Oddler's user avatar
  • 6,618
2 votes
0 answers
81 views

SQLite Query does not return data when "T" is included in datetimes in the WHERE clause

The following query doesn't return any data: SELECT "t0"."id" AS "res0", "t0"."time" AS "res1", "t1"."name" AS "...
Cristian Motoche's user avatar
0 votes
1 answer
58 views

Types conversion from one package to other

I'm starting with Haskell in an RSA crypto project. Digging in Hackage, I found two different packages to achieve my objective. The problem is that each package has its own version of the same type (...
Albert's user avatar
  • 1
0 votes
1 answer
44 views

Haskell ForeignPtr finalizer with two environments

The problem is FFI wrapping a C-Type that requires two environment variables for initialization and de-allocation with a ForeignPtr More concretely I want to wrap void gr_mpoly_init(gr_mpoly_t A, ...
Hartmut Monien's user avatar
0 votes
1 answer
81 views

type classes act as interfaces (??)

After reading about type classes in Haskell, I thought them as like Java interfaces You define a set of methods in your type class (Num) and any data/newtype(Foo) declared type, if it wants to be part ...
kichii112's user avatar
3 votes
1 answer
74 views

How to build lens expression dynamically?

I have the following code snippet that reads a value specified by a lens (lens-aeson) expression: import Control.Lens ((^?)) import Data.Aeson (Value) import Data....
Joe's user avatar
  • 343
0 votes
0 answers
71 views

Can this Discrete Program Search have improved asymptotics in Haskell?

I've been researching how to use optimal evaluation to optimize Discrete Program Search and I arrived at a simple solution that seems to be really effective. Based on the following tests: f 1001101110 ...
MaiaVictor's user avatar
  • 52.6k
1 vote
1 answer
94 views

Dynamic Programming in Haskell. Is this the correct way (?)

Haskell does not allow mutating a global variable, which is the key concept of Dynamic Programming, so I come up with a solution. This relies on Haskell's lazy evaluation and infinite lists Is it ...
kichii112's user avatar
1 vote
1 answer
49 views

Why is UndecidableInstances not required here, for instance C1

Trying this in other contexts requires the extension (which seems right), but not here: {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE QuantifiedConstraints #-} import Data.Kind (Type) class (forall a. ...
jberryman's user avatar
  • 16.6k
0 votes
0 answers
37 views

GenProg for Haskell

I am linking to a similar question in which the person seemed to get it working. However, with the instructions I have followed nothing seems to work to get Haskell running. System: Ubuntu 22.04 1) ...
wookieluvr's user avatar
1 vote
0 answers
59 views

Haskell PatternSynonyms bang strictness annotation

The User Guide comment says this is not allowed, but the explicitly bidir form is pattern StrictJust a = Just !a pattern StrictJust a <- Just !a where StrictJust !a = Just a Given that the ...
AntC's user avatar
  • 2,806
2 votes
2 answers
76 views

How can I "suppress" concurrent "forever-running" actions from main thread upon user input?

This program {-# LANGUAGE LambdaCase #-} import Control.Concurrent (threadDelay) import Control.Concurrent.Async (withAsync) import Control.Exception (finally) import Control.Monad (forever) main :: ...
Enlico's user avatar
  • 27.2k
1 vote
1 answer
53 views

Is there a way to locally (i.e. on my machine) check my cabal project dependencies against whatever environment Hackage provides?

The foreword is the same as my previous question Some time ago I worked on this project, and I experimented a bit with package candidates. Then, yesterday, I uploaded the real package on hackage. ...
Enlico's user avatar
  • 27.2k
5 votes
1 answer
60 views

What determines what GHC (and Cabal, and HLS, ...) version is marked as "recommended" in GHCup?

I tend to stick to "recommended" versions: ┌──────────────────────────────────GHCup──────────────────────────────────┐ │ Tool Version Tags Notes ...
Enlico's user avatar
  • 27.2k
1 vote
0 answers
43 views

How to restrict the type of an instance when the instance requires a "* -> *" type in Haskell? [duplicate]

I'm trying to design a type that holds some value and keeps track of all operations done upon it. It does this by storing them in string format (this is not for a project, just learning) I tried to ...
SHIPWECK's user avatar
0 votes
1 answer
77 views

Type-level tuple: how to avoid nesting in a type argument

Considering first-class-families library, I have a code: import Fcf.Data.Common import Fcf.Core type T a b c = '(a, '(b, c)) ...
RandomB's user avatar
  • 3,677
0 votes
1 answer
74 views

Constant function optimization

If I have a function fun like: -- For example, `SomeRecord` can have more than 2 fields, -- but 20 or 30 data SomeRecord a b = SomeRecord { f1 :: a -> b, f2 :: a -> b -> Bool } fun :: ...
RandomB's user avatar
  • 3,677
2 votes
0 answers
81 views

Possible explanations for an operation hanging indefinitely with a redundant constraint?

During a GHC upgrade we noticed one particular test case seemed to just hang forever (at runtime, not compile time). In searching for a looping bottom value lurking somewhere I found a startling fact, ...
jberryman's user avatar
  • 16.6k
6 votes
2 answers
99 views

How laziness works with applicative functors in Haskell?

I don’t quite understand how functions behave when working with applicative functors. Here's an example: ghci> (&&) <$> Just False <*> undefined *** Exception: Prelude.undefined ...
Leonid's user avatar
  • 63
2 votes
2 answers
113 views

How does liftM2 work like the S' combinator in Haskell?

I was watching a video by code_report (Link) where he mentions liftM2 works like the S' combinator from combinatory logic. In his example he calculates the min/max element of an array and takes their ...
nessel's user avatar
  • 33
-4 votes
1 answer
79 views

How could I get an infinite loop of some video streams with gstreamer and haskell?

I am following the tutorial from https://github.com/haskell-gi/haskell-gi/blob/master/examples/advanced/GstHelloWorld.hs , I'm trying to modify it so that I can have Gstreamer play some video files on ...
Ciuppo's user avatar
  • 43
2 votes
2 answers
97 views

Confusion between GHCup and Cabal as regards versions of installed packages (system-wise and in specific cabal projects)

This is what I see when I run ghcup tui in a terminal in $HOME: ┌──────────────────────────────────GHCup──────────────────────────────────┐ │ Tool Version Tags ...
Enlico's user avatar
  • 27.2k
0 votes
0 answers
46 views

How to deal with upstream version bounds changes when uploading/updating a package on Hackage? (And why don't I get the same errors on my machine?)

Some time ago I worked on this project, and I experimented a bit with package candidates. Then, yesterday, I uploaded the real package on hackage. However, it fails to build. I think the reason is ...
Enlico's user avatar
  • 27.2k
-1 votes
2 answers
77 views

How to change the base case so it starts recursion all over?

I am trying to force a recursion to loop infinitely for a project of mine. This is my code up so far: putStr' :: String -> IO () putStr' (a:as) = do putChar a putChar '\n' ...
Ciuppo's user avatar
  • 43
1 vote
1 answer
126 views

Constructor classes: why not mention the content's type?

Following on from this q about monad transformers ... Before constructor classes were introduced [M.P.Jones 1993], Haskell class decls: Must have a single parameter; That parameter must be kind Type (...
AntC's user avatar
  • 2,806
1 vote
1 answer
53 views

If we bind two parsers and the second parser fails, does the string get parsed once?

So suppose this is a parser: data Parser a = MkParser (String -> Maybe (String, a)) runParser :: Parser a -> String -> Maybe a runParser (MkParser sf) inp = case sf inp of ...
user20102550's user avatar
1 vote
1 answer
46 views

How to parse CFG with operators

Ok so I have this parser and data: module SO where import Data.Char import Prelude hiding (fmap, (>>=), (*>), (<*), pure) data Parser a = MkParser (String -> Maybe (String, a)) data ...
user20102550's user avatar

1
2 3 4 5
1030