51,795 questions
5
votes
2
answers
88
views
Ambigous type variable in tagless final mini language
Fur fun and education I'm trying to write a mini compiler with the final tagless method as described by
Oleg Kiselyov in his paper Typed Tagless Final Interpreters.
My grammar has expressions and ...
7
votes
1
answer
111
views
What is the formal name for GHC automatically adapting less-constrained functions to more-constrained rank-2 arguments?
Consider this Haskell code that compiles successfully:
{-# LANGUAGE RankNTypes #-}
-- Applies a polymorphic function to different types, expecting 3 constraints
applyToMany :: (forall a. (Show a, Eq ...
4
votes
1
answer
91
views
Understanding usage of withFileBlocking with named pipes
The following program
assumes that /path/to/mypipe is a named pipe, e.g. created via mkfifo /path/to/mypipe, with no readers/writers waiting yet,
runs two threads, of which
the main thread keeps ...
0
votes
1
answer
137
views
How do I make the "return" function from the Monad class return a phantom parameter?
MRE:
module Temp where
data Some r a = Thing r a
instance Monad (Some r) where
return :: a -> Some r a
return a = Thing r a -- <- The is a phantom argument (somewhat like the s in ...
2
votes
2
answers
126
views
Merge every element of 2 lists of lists
Suppose, we have 2 lists of lists:
a = [[1,2], [3,4]]
b = [[5,6], [7,8]]
We want to merge every element of the first list with every element of the second list and get:
c = [[1,2,5,6], [1,2,7,8], [3,...
3
votes
1
answer
74
views
Is there a way to check for an instance of a class (with Haskell extensions)?
I am currently writing common theorems of intuitionistic logic in Haskell using the Curry-Howard isomorphism:
import Data.Void
type a :> b = a -> b -- implies
type a :+ b = Either a b -- or
data ...
2
votes
1
answer
72
views
On implementing map in terms of fold for a binary tree in Haskell
I've been making progress with Chris Allen's Haskell book and I am stumped in an exercise as the title suggests.
First of all, the binary tree is defined as such:
data BinTree a = Leaf | Node (...
5
votes
2
answers
118
views
Haskell ghci ocupying too much memory
I encountered a problem where my ram explodes and I really don't know why.
the code to read a csv is:
--module
splitComma _ [] = [[]]
splitComma False (',':t) = [[]]++splitComma False t
splitComma ...
4
votes
1
answer
91
views
How does the point-free expression ((*) .) . (*) work in Haskell?
I'm learning about Haskell and came across this concise, but weird, definition for a function that multiplies three numbers:
volume :: Float -> Float -> Float -> Float
volume = ((*) .) . (*)
...
3
votes
2
answers
85
views
Why doesn't readFile block on unix pipe in which no write has happened yet?
If in a terminal I enter
mkfifo /tmp/pipe
echo hello > /tmp/pipe
(which blocks) and in another I run the haskell program
main = readFile "/tmp/foobar" >>= putStr
then I see it ...
3
votes
1
answer
70
views
Polymorphic function in class and polymorphic instance: how to bind parameter types?
I want to recursively collect arguments of a function to a tuple with nesting (the general idea is taken from here).
I have a class with a function with polymorphic parameter (a, b). I want to make an ...
1
vote
1
answer
70
views
What does it mean that the arguments to <*> and their associated effects are known statically?
I'm reading the paper Selective Applicative Functors. So far I've read from page 16 out 29, and I think I've understood the gist of this abstraction, but I'm having some trouble with some basic ...
1
vote
1
answer
76
views
Understanding behavior of DBus with respect to killing the process that used DBus to register a name
Take this simple program in Haskell
{-# LANGUAGE OverloadedStrings #-}
import Control.Exception (finally)
import Control.Monad (forever)
import Xmobar (tenthSeconds)
import DBus.Client
startServer' :...
1
vote
1
answer
74
views
Under what circumstances can a write to a Haskell unsafeThaw-ed array/vector result in a segfault (via lost GC root)?
This question tries to collect the full picture if/when a stale object reference can happen from an old-gen (immutable) array referring a newer-gen object, from fragments of information.
Preface: was ...
1
vote
1
answer
59
views
Any memory safety concerns when using Haskell's vector unsafeFreeze / unsafeThaw on unpinned vector?
Apart from the known safety concerns documented for unsafeFreeze / unsafeThaw, is there any issue using these functions with non-pinned backing data (that is, as I understand everything except Vector....