Search Haskell Channel Logs

Tuesday, February 28, 2017

#haskell channel featuring Ptival, cocreature, osa1,

Ptival 2017-02-28 19:45:46
what indentation mode do emacs users use? I'm getting frustrated by the lack of support of standalone deriving in the one I have now
osa1 2017-02-28 19:50:36
my indentation script just follows the line before on enter, it works great.
Ptival 2017-02-28 19:52:23
nvm, I found out https://github.com/haskell/haskell-mode/pull/1276 it was recently fixed
cocreature 2017-02-28 19:52:55
hrumph: I'm not aware of any library that provides this

#haskell channel featuring kadoban, nshepperd, jle`, sjakobi, hrumph, Cale,

Cale 2017-02-28 18:45:13
Well, yeah
jle` 2017-02-28 18:46:07
is there any nice way to write '(,) a b
jle` 2017-02-28 18:46:12
the type
nshepperd 2017-02-28 18:46:28
even though I don't really see why because it's a function inside?
nshepperd 2017-02-28 18:46:41
like, it's not even const ⊥
nshepperd 2017-02-28 18:47:18
I guess probably performance reasons outweigh being able to do tricks like fix sin
Younder 2017-02-28 18:48:01
Well are you familiar with Pythons implementation of numbers in it's original form. Incredibly inefficient. Feels something like that. So ADA using Python implementation methods. Neither fish nor foul!
Cale 2017-02-28 18:49:59
Younder: It's almost surely more inefficient than that (but also does more)
sjakobi 2017-02-28 18:55:19
Quick heads-up that Hackage has lost a few packages: https://github.com/haskell/hackage-server/issues/573
sjakobi 2017-02-28 18:56:45
stack users might run into a strange issue with nightly-2017-03-01 which contains one or more of these lost packages.
kadoban 2017-02-28 19:00:23
Uh oh
hrumph 2017-02-28 19:30:13
hi
hrumph 2017-02-28 19:32:51
hi
hrumph 2017-02-28 19:33:03
i'm looking for something you might call a "degenerate monad" or something like that
hrumph 2017-02-28 19:33:07
http://lpaste.net/353088
hrumph 2017-02-28 19:33:15
is there a standard designation for this?

#haskell channel featuring Younder, lambdabot, pikajude, threshold, davean, Koterpillar,

davean 2017-02-28 17:45:12
go #ghc
Koterpillar 2017-02-28 17:46:12
nshepperd: well, sin undefined <= 1
nshepperd 2017-02-28 17:57:04
fix (\x -> x / 100) would work in a decimal bounded setting (0 < x < 1), then you could do x/100 = 0:0:x
Cale 2017-02-28 17:57:07
Koterpillar: But then the next step gets you, you would presumably want to know that sin (sin undefined) <= sin 1, however, to get that, you need to know something more subtle about the sine function, such as the fact that it's monotonic on [0,1]
Koterpillar 2017-02-28 18:08:16
Cale: if I (somehow) compute sine starting from the most significant digit, then since head (sin undefined) == 0, that gives me a _better_ upper bound on sin (sin undefined)
Cale 2017-02-28 18:09:42
How though?
Cale 2017-02-28 18:09:56
I know that by using arbitrary amounts of analysis you can get that
Cale 2017-02-28 18:12:11
Just knowing that sin (undefined) < 1 doesn't tell you much about sin (sin undefined) unless you know something about sine itself, such as monotonicity in an interval.
Cale 2017-02-28 18:12:47
In particular, without something special, you're not going to obtain sin (sin undefined) < sin 1 like you want
threshold 2017-02-28 18:14:14
Do the integers for a partially ordered set with respect to the order ≤ ?
threshold 2017-02-28 18:14:18
form
Cale 2017-02-28 18:17:30
yes
Cale 2017-02-28 18:17:43
(moreover, they're totally ordered)
pikajude 2017-02-28 18:18:44
duuude
nshepperd 2017-02-28 18:23:12
I think you need to take advantage of one the trigonometric identities involving sin to do this. and to be able to express such identity as a constructor of your real number type
nshepperd 2017-02-28 18:23:40
it seems like it might be possible, but I don't know how
Cale 2017-02-28 18:24:50
Yeah, maybe if you contrived your representation of the reals around the ability to do this :)
Cale 2017-02-28 18:25:43
(i.e. cheating by building in sine-related stuff)
nshepperd 2017-02-28 18:27:27
well, not quite cheating
nshepperd 2017-02-28 18:27:40
I mean, putting in a Sin constructor wouldn't help at all
nshepperd 2017-02-28 18:28:30
I was thinking of continued fractions or something but I don't really know
Cale 2017-02-28 18:28:34
It might help :)
Cale 2017-02-28 18:28:56
(though it would make the implementation of all your operations really annoying)
nshepperd 2017-02-28 18:30:05
show x@(Sin y) | accursedUnutterablePtrEquality x y = "0" -- :)
Koterpillar 2017-02-28 18:32:13
a bounded constructor will help, probably
Koterpillar 2017-02-28 18:32:54
data BReal = ExactValue Float | Between Float Float BReal
Younder 2017-02-28 18:33:52
Quirky ADA :)
nshepperd 2017-02-28 18:34:39
hmm.... a sequence of decreasing bounds, perhaps
nshepperd 2017-02-28 18:34:44
this sounds familiar
Koterpillar 2017-02-28 18:36:05
I thought this was how CReal was implemented anyway?
Cale 2017-02-28 18:36:46
iirc, CReal is implemented as a sequence of rational numbers such that the nth is within 1/2^n of the limit.
nshepperd 2017-02-28 18:37:17
sin x 0 = Between (-1) 1; sin x n = Between { some function of (x (n-1)) }
Cale 2017-02-28 18:37:17
So that effectively gives you a sequence of intervals of decreasing size
Cale 2017-02-28 18:37:53
nshepperd: that first bit is a type error... ;)
Younder 2017-02-28 18:38:19
How are the size and computational properties of CReal?
Cale 2017-02-28 18:38:44
It's fairly impractical
Cale 2017-02-28 18:38:52
It's okay for some things
nshepperd 2017-02-28 18:38:56
Cale: nah, I'm talking about numbers that are functions now
nshepperd 2017-02-28 18:39:05
the Int -> a kind of sequence
Cale 2017-02-28 18:39:35
> sum [1..1000] :: CReal
lambdabot 2017-02-28 18:39:42
mueval-core: Time limit exceeded
Cale 2017-02-28 18:39:49
^^ but it's pretty bad for general computation
Cale 2017-02-28 18:43:32
> exp (pi * sqrt 163) :: CReal
lambdabot 2017-02-28 18:43:36
262537412640768743.9999999999992500725971981856888793538563
Cale 2017-02-28 18:43:46
^^ not that bad so long as the expression is simple
nshepperd 2017-02-28 18:44:33
so in conclusion, I feel like maybe CReal or something like it should be able to do this, but I don't really understand its implementation
nshepperd 2017-02-28 18:44:58
unfortunately sin ⊥ is actually ⊥ in CReal though

#haskell channel featuring lambdabot, nshepperd, Squarism, orion, threshold, monochrom,

MarcelineVQ 2017-02-28 16:50:49
Squarism 2017-02-28 17:11:06
Any threading person that could do a sanity check : ok to "send a channel over a channel"?
monochrom 2017-02-28 17:11:36
Yes. The pi calculus does that all the time.
orion 2017-02-28 17:16:29
:t fix
lambdabot 2017-02-28 17:16:32
(a -> a) -> a
nshepperd 2017-02-28 17:17:19
Squarism: that seems perfectly fine to me
Squarism 2017-02-28 17:17:53
nshepperd, thanks
nshepperd 2017-02-28 17:17:54
you're just putting an mvar in an mvar, which channel already does
Koterpillar 2017-02-28 17:20:46
what's that computable float type that makes it possible to fix sin?
monochrom 2017-02-28 17:21:21
Is it CReal?
Koterpillar 2017-02-28 17:22:16
fix sin :: CReal
Koterpillar 2017-02-28 17:22:17
> fix sin :: CReal
lambdabot 2017-02-28 17:22:23
mueval-core: Time limit exceeded
Koterpillar 2017-02-28 17:23:39
> fix (\x -> x / 100) :: CReal
lambdabot 2017-02-28 17:23:45
mueval-core: Time limit exceeded
Koterpillar 2017-02-28 17:23:50
how come this doesn't converge either?
nshepperd 2017-02-28 17:41:47
for those to work you'd need sin undefined ≠ undefined
threshold 2017-02-28 17:42:35
Koterpillar: What do you mean by converge?
nshepperd 2017-02-28 17:42:38
it would have to be some weird representation with lazy continued fractions or something o_O
threshold 2017-02-28 17:43:31
nshepperd: Thank you for the Stack Overflow link. I will read through it.

#haskell channel featuring suica, raynold, pacak, doomlord, pikajude, benzrf, and 12 others.

doomlord 2017-02-28 15:47:45
one thing that bugged me about haskell was the lack of 'dot' accessor syntax (dot is used for function composition?) .. do they have an operator like that these days. "object.field" I seem to remember being told haskell concention is always to write expressions 'right to left' (e.g. $ operator) instead of 'left to right' (the threading macro in clojure)
Koterpillar 2017-02-28 15:48:18
there's & if you want it
marchelzo 2017-02-28 15:48:37
you mean like for accessing fields of records?
Koterpillar 2017-02-28 15:48:48
:t (&)
lambdabot 2017-02-28 15:48:51
a -> (a -> b) -> b
marchelzo 2017-02-28 15:49:07
you can use lens for that and then you can just use regular . to compose
Koterpillar 2017-02-28 15:49:24
so if you have data Data = { foo :: Int, bar :: String }, then this works: data & foo
Koterpillar 2017-02-28 15:49:33
and with lenses, data & foo.bar.baz
Koterpillar 2017-02-28 15:49:48
or even without lenses
tibbe 2017-02-28 15:50:14
I'm trying to use ConstraintKinds to alias a MonadReader: type EnvM m n = MonadReader (Env n) m
tibbe 2017-02-28 15:50:19
where Env is a concrete data type
tibbe 2017-02-28 15:50:29
but I get: Non type-variable argument in the constraint: MonadReader (Env n) m
tibbe 2017-02-28 15:50:36
why isn't this working? :)
tibbe 2017-02-28 15:52:32
I'm just trying to create a new, more specialized version of the MonadReader type class (i.e. with the environment fixed)
robkennedy 2017-02-28 15:56:07
@hoogle (b -> c -> t b c) -> (a -> Maybe b) -> (a -> Maybe c) -> (a -> Maybe (t b c))
lambdabot 2017-02-28 15:56:10
Control.Monad.HT liftJoin4 :: Monad m => (a -> b -> c -> d -> m e) -> m a -> m b -> m c -> m d -> m e
lambdabot 2017-02-28 15:56:11
Control.Concatenative biSpM :: Monad m => (a -> m c) -> (b -> m d) -> (c -> d -> m e) -> a -> b -> m e
lambdabot 2017-02-28 15:56:11
Control.Concatenative triM :: Monad m => (a -> m b) -> (a -> m c) -> (a -> m d) -> (b -> c -> d -> m e) -> a -> m e
pikajude 2017-02-28 15:56:50
robkennedy: try liftA2
robkennedy 2017-02-28 15:57:03
:t liftA2
lambdabot 2017-02-28 15:57:05
Applicative f => (a -> b -> c) -> f a -> f b -> f c
pikajude 2017-02-28 15:57:18
> liftA2 (,) (Just 3) (just 4)
lambdabot 2017-02-28 15:57:21
error:
lambdabot 2017-02-28 15:57:21
• Variable not in scope: just :: Integer -> Maybe b
lambdabot 2017-02-28 15:57:21
• Perhaps you meant data constructor 'Just' (imported from Data.Maybe)
pikajude 2017-02-28 15:57:21
> liftA2 (,) (Just 3) (Just 4)
pikajude 2017-02-28 15:57:24
whoops
lambdabot 2017-02-28 15:57:25
Just (3,4)
suica 2017-02-28 15:58:52
is lpaste.net down? related to S3 issues?
robkennedy 2017-02-28 15:59:02
:t liftA2 (,) listToMaybe (\l -> if null l then Nothing else Just (sum l)) [1..5]
lambdabot 2017-02-28 15:59:05
(Num t, Enum t) => (Maybe t, Maybe t)
robkennedy 2017-02-28 15:59:41
pikajude: I'm hoping to join them
threshold 2017-02-28 15:59:48
I am learning about the fixed point of a functor, Fix, by reading http://www.haskellforall.com/2012/06/you-could-have-invented-free-monads.html
pikajude 2017-02-28 15:59:48
what's in them
robkennedy 2017-02-28 16:00:46
Well if I have two functions I'm hoping to get Nothing if failure happens in either.
threshold 2017-02-28 16:01:05
Given data Toy b next = Output b next | Bell next | Done and data Fix f = Fix (f (Fix f)) What is going on here? Fix (Output 'A' (Fix Done)) :: Fix (Toy Char)
dfeuer 2017-02-28 16:04:47
*headshake*. containers is full of unresolved GitHub issues, and I absolutely don't have time to work through most of them soon. (Which isn't to say I haven't been working on containers; just a lot of work all around.)
hpc 2017-02-28 16:05:14
threshold: when used with Fix, next = Fix (Toy b)
hpc 2017-02-28 16:05:17
so it's like writing
hpc 2017-02-28 16:05:27
data Toy b = Output b (Toy b) | Bell (Toy b) | Done
hpc 2017-02-28 16:06:20
to do it with Fix, you need to add the Fix data constructor in a few places
hpc 2017-02-28 16:07:50
threshold: how much have you done with fix at the value level?
EvanR 2017-02-28 16:08:12
i waiting for the article on "you could have invented free monad monad monad algebras"
pikajude 2017-02-28 16:08:31
the "you could have invented this" free monad
hpc 2017-02-28 16:09:20
i can't wait for the retrospective on haskell
hpc 2017-02-28 16:09:26
"'you could have invented lens' and other falsehoods"
hpc 2017-02-28 16:10:11
threshold: anyhoo, any understanding you are able to carry over from fix will also apply to Fix
hpc 2017-02-28 16:10:15
which can make it easier
threshold 2017-02-28 16:11:40
hpc: Today is the first day that I've heard of a fixed point, so I have very little experience with fix
raynold 2017-02-28 16:14:43
ahh it's a wonderful day
threshold 2017-02-28 16:24:59
Maybe a better question is how does fix work?
threshold 2017-02-28 16:25:27
@src fix
lambdabot 2017-02-28 16:25:28
fix f = let x = f x in x
barrucadu 2017-02-28 16:29:33
Perhaps a more readable definition if `fix f = f (fix f)`
barrucadu 2017-02-28 16:29:34
*is
threshold 2017-02-28 16:30:25
barrucadu: That is still mind boggling
threshold 2017-02-28 16:30:42
How do you use it?
threshold 2017-02-28 16:32:10
https://en.wikipedia.org/wiki/Fixed_point_(mathematics) should be useful in understanding?
barrucadu 2017-02-28 16:33:11
`fix` lets you do recursion without giving a name to your recursive function
barrucadu 2017-02-28 16:33:32
> fix (\go x -> if x == 0 then 1 else x * go (x-1)) 5 -- factorial
lambdabot 2017-02-28 16:33:34
120
nshepperd 2017-02-28 16:39:25
threshold: fix returns the 'least' fixed point of the function, in the domain theory sense
Squarism 2017-02-28 16:40:22
does it sound sane to "send a channel over a channel" ? =D
benzrf 2017-02-28 16:41:16
threshold: `fix f' is a fixpoint of f in a very boring way, by definition
benzrf 2017-02-28 16:41:39
threshold: `fix f' expands to `f (fix f)' by definition, so naturally `fix f = f (fix f)'
benzrf 2017-02-28 16:41:50
then `fix f' is a fixpoint, in a very cheating-y way
benzrf 2017-02-28 16:42:25
intuitively, if you have an infinitely deeply nested list of applications of f, like `f (f (f (f (f ...))))', then adding another f won't hurt
nshepperd 2017-02-28 16:42:39
threshold: I guess http://stackoverflow.com/a/4787577 is the thing to read
benzrf 2017-02-28 16:42:53
but note that this is only useful if you have lazy evaluation - with strict evaluation, this is always an infinite loop
benzrf 2017-02-28 16:43:14
`fix f' is quite often still an infinite loop in haskell, but not always:
benzrf 2017-02-28 16:43:17
> fix (+1)
lambdabot 2017-02-28 16:43:23
mueval-core: Time limit exceeded
benzrf 2017-02-28 16:43:24
> fix (1:)
lambdabot 2017-02-28 16:43:28
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1...
benzrf 2017-02-28 16:43:47
`1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + ...' is undefined, of course, but `1:1:1:1:1:1:1:...' makes sense!
pacak 2017-02-28 16:43:55
> fix error
lambdabot 2017-02-28 16:43:59
"*Exception: *Exception: *Exception: *Exception: *Exception: *Exception: *Ex...
benzrf 2017-02-28 16:44:03
:}
pacak 2017-02-28 16:44:08
Exceptions all the way down!
benzrf 2017-02-28 16:44:27
@let me = const (text "Some things are unfixable.")
lambdabot 2017-02-28 16:44:31
Defined.
benzrf 2017-02-28 16:44:31
> fix me
lambdabot 2017-02-28 16:44:35
Some things are unfixable.
nshepperd 2017-02-28 16:44:46
:{

#haskell channel featuring glguy, dolio, mniip, hpc, Wizek,

Wizek 2017-02-28 14:55:07
Hey, anyone knows why this throws an exception instead of returning Left? `parseTimeM True defaultTimeLocale "%Y" "a" $> either (show .> ("fail: "<>)) ((show :: UTCTime -> _) .> ("parse: "<>)) where ($>) = flip ($)`
glguy 2017-02-28 14:56:24
because fail for either doesn't return a Left
glguy 2017-02-28 14:56:45
and that function is unfortunately defined to use fail for errors
Wizek 2017-02-28 14:56:58
that does sound deeply unfortunate
Wizek 2017-02-28 14:57:08
how come?
glguy 2017-02-28 14:57:27
you'd have to ask the author
hpc 2017-02-28 14:57:36
mniip: er, forgot about https://downloads.haskell.org/~ghc/7.8.2/docs/html/users_guide/roles.html too
mniip 2017-02-28 14:58:15
hpc, ???
hpc 2017-02-28 14:58:25
and the docs for State#
hpc 2017-02-28 14:59:02
basically, State# a has no underlying representation
hpc 2017-02-28 14:59:26
and in the unboxed tuple, the whole representation is just b
mniip 2017-02-28 14:59:27
right
hpc 2017-02-28 14:59:44
for IO that means IO a has the same representation as a
hpc 2017-02-28 14:59:50
which means ghc haskell is impure
hpc 2017-02-28 15:00:01
which it must necessarily be in order to admit unsafePerformIO in the first place
mniip 2017-02-28 15:00:16
I was asking a fairly specific question about calling conventions
mniip 2017-02-28 15:00:21
not generic IO stuff
hpc 2017-02-28 15:00:31
ah nvm then
mniip 2017-02-28 15:00:53
just noticed that you can operate on (# State# a, b #) in ghci without object code
mniip 2017-02-28 15:01:10
which means that by the time it hits the codegen there is already no unbox tuple
hpc 2017-02-28 15:03:06
probably part of the magic of State#
dolio 2017-02-28 15:08:13
I don't think representing `IO a` the same way as `a` necessarily makes you impure. It's giving access to that representation that makes you impure.
hpc 2017-02-28 15:12:18
dolio: yeah, i was taking a bit of license there ;)
hpc 2017-02-28 15:12:33
it's a pretty neat thing to learn for the first time though

#haskell channel featuring Forkk, Ptival, Tuplanolla, glguy, mniip, lambdabot,

EvanR 2017-02-28 13:45:13
you can import Prim something to deconstruct Integer to get a pointer to gmp object
EvanR 2017-02-28 13:45:30
im not sure about what you do in C though
Forkk 2017-02-28 13:47:03
what if the garbage collector deletes the integer while C is using it though
lambdafan 2017-02-28 13:48:05
@type a -> m (a -> b) -> m b
lambdabot 2017-02-28 13:48:06
error: parse error on input '->'
lambdafan 2017-02-28 13:48:15
@type (a -> m (a -> b) -> m b)
lambdabot 2017-02-28 13:48:17
error:
lambdabot 2017-02-28 13:48:17
Pattern syntax in expression context: a -> m (a -> b) -> m b
lambdabot 2017-02-28 13:48:17
Did you mean to enable TypeApplications?
lambdafan 2017-02-28 13:48:48
@djinn (a -> m (a -> b) -> m b)
lambdabot 2017-02-28 13:48:48
-- f cannot be realized.
glguy 2017-02-28 13:48:52
lambdabot: What are you trying to do?
lambdafan 2017-02-28 13:49:05
@djinn a -> m (a -> b) -> m b
lambdabot 2017-02-28 13:49:05
-- f cannot be realized.
Sornaensis 2017-02-28 13:49:12
@kind (a -> (a -> b) -> b)
lambdabot 2017-02-28 13:49:14
error: Not in scope: type variable 'a'
lambdabot 2017-02-28 13:49:14
error: Not in scope: type variable 'a'
lambdabot 2017-02-28 13:49:14
error: Not in scope: type variable 'b'
lambdafan 2017-02-28 13:49:19
I'm trying to find the operator with that type
Sornaensis 2017-02-28 13:49:42
@hoogle a -> m (a -> b) -> m b
mniip 2017-02-28 13:49:43
:t fmap . flip id
Tuplanolla 2017-02-28 13:49:45
:t \ x f -> f <*> pure x
lambdabot 2017-02-28 13:49:45
Functor f => b1 -> f (b1 -> b) -> f b
lambdabot 2017-02-28 13:49:45
Control.Lens.Getter contramap :: (a -> b) -> f b -> f a
lambdabot 2017-02-28 13:49:45
Data.Functor.Compat fmap :: (a -> b) -> f a -> f b
lambdabot 2017-02-28 13:49:45
Data.Functor.Apply fmap :: (a -> b) -> f a -> f b
lambdabot 2017-02-28 13:49:47
Applicative f => a -> f (a -> b) -> f b
mniip 2017-02-28 13:50:13
it is not doable for a generic f
mniip 2017-02-28 13:50:21
hence djinn's failing
glguy 2017-02-28 13:50:35
:t flip (??)
EvanR 2017-02-28 13:50:36
Forkk: well, you have a reference to it, so not sure if thats possible
lambdabot 2017-02-28 13:50:38
Functor f => a -> f (a -> b) -> f b
Sornaensis 2017-02-28 13:51:04
@hoogle Functor f => a -> f (a -> b) -> f b
lambdabot 2017-02-28 13:51:05
Prelude fmap :: Functor f => (a -> b) -> f a -> f b
lambdabot 2017-02-28 13:51:05
Prelude (<$>) :: Functor f => (a -> b) -> f a -> f b
lambdabot 2017-02-28 13:51:05
Control.Monad fmap :: Functor f => (a -> b) -> f a -> f b
lambdafan 2017-02-28 13:51:29
@hoogle a -> m (a -> b) -> m b
lambdabot 2017-02-28 13:51:42
Control.Lens.Getter contramap :: (a -> b) -> f b -> f a
lambdabot 2017-02-28 13:51:42
Data.Functor.Compat fmap :: (a -> b) -> f a -> f b
lambdabot 2017-02-28 13:51:42
Data.Functor.Apply fmap :: (a -> b) -> f a -> f b
mniip 2017-02-28 13:51:42
lambdafan, you were already given an answer
Forkk 2017-02-28 13:51:42
EvanR: C code having a pointer to it doesn't count I don't think
Forkk 2017-02-28 13:51:42
I suppose I could copy it
glguy 2017-02-28 13:51:42
lambdabot: You can mess around with lambdabot in /msg
glguy 2017-02-28 13:51:43
lambdafan: : You can mess around with lambdabot in /msg
lambdafan 2017-02-28 13:51:47
ah, thanks :)
EvanR 2017-02-28 13:51:49
haskell code will have a reference to it
mniip 2017-02-28 13:52:14
EvanR, that depends on the code
Forkk 2017-02-28 13:52:16
that's not guaranteed
mniip 2017-02-28 13:52:35
you can easily have it unreferenced just as the gmp object goes into ffi
EvanR 2017-02-28 13:52:52
i mean, a reference to the object itself
mniip 2017-02-28 13:52:55
and gmp objects are what? Addr#?
EvanR 2017-02-28 13:52:58
if the integer wrapper is gone, so what
Forkk 2017-02-28 13:53:44
also, can gmp even be used in called C code
Forkk 2017-02-28 13:54:02
I've heard there were issues, but I can't find anything specific saying they were fixed
mniip 2017-02-28 13:54:13
aha
mniip 2017-02-28 13:54:17
it's a ByteArray#
mniip 2017-02-28 13:54:25
which can be spontaneously moved
EvanR 2017-02-28 13:54:56
ByteArray# can?
mniip 2017-02-28 13:55:07
if it's not pinned?
EvanR 2017-02-28 13:55:09
i know whatever ByteString uses cant
mniip 2017-02-28 13:55:21
hmm
mniip 2017-02-28 13:55:29
or was it mutable byte arrays
Forkk 2017-02-28 13:55:47
so integers are stored as byte arrays?
mniip 2017-02-28 13:56:12
Forkk, more like unpacked mpz_t
Forkk 2017-02-28 13:56:34
right
Forkk 2017-02-28 13:56:39
so how would I turn that into an mpz_t in C
Forkk 2017-02-28 13:58:22
I'd probably want to have it copy it so it's not subject to the GC
mniip 2017-02-28 13:59:52
ah
mniip 2017-02-28 13:59:55
1.0.0.1 changed it
lambdafan 2017-02-28 14:00:04
can lambdabot tell me the fixity of an operator?
glguy 2017-02-28 14:00:13
no, but GHCi can do that, too
Sornaensis 2017-02-28 14:00:33
lambdafan: :info at ghci prompt
lambdafan 2017-02-28 14:00:39
:)
mniip 2017-02-28 14:00:48
Forkk, so, well, there's
mniip 2017-02-28 14:01:05
mp_limb_t mpn_add (mp_limb_t *rp, const mp_limb_t *s1p, mp_size_t s1n, const mp_limb_t *s2p, mp_size_t s2n)
mniip 2017-02-28 14:01:13
in gmp lowlevel functions
Forkk 2017-02-28 14:01:30
ok
mniip 2017-02-28 14:01:38
and then integer-gmp just foreign imports that, and passes the bytearrays as limb arrays
mniip 2017-02-28 14:02:33
you could convert it into an mpz_t in accordance with https://gmplib.org/manual/Integer-Internals.html
EvanR 2017-02-28 14:03:16
so a less pain in the ass way might be
EvanR 2017-02-28 14:03:39
render the integer as a CString, pass that through ffi, load the string into gmp on the other side
EvanR 2017-02-28 14:03:44
and vice versa
Forkk 2017-02-28 14:04:17
lol
Forkk 2017-02-28 14:04:42
I think that may work
Forkk 2017-02-28 14:05:11
I could just drop in a better replacment later if necessary
mniip 2017-02-28 14:05:30
I would recommend formatting them to hexadecimal and loading with 0x and base=0
mniip 2017-02-28 14:05:34
as a premature optimization
Forkk 2017-02-28 14:06:05
and in case gmp doesn't work this way I could use something else
EvanR 2017-02-28 14:06:10
"I would recommend... premature optimization" ;)
Forkk 2017-02-28 14:06:24
lol
mniip 2017-02-28 14:06:33
but divisions by 10
EvanR 2017-02-28 14:06:46
this is the simplest possible thing that will work
EvanR 2017-02-28 14:06:56
humongs love base 10
Forkk 2017-02-28 14:07:39
thanks for the suggestion
mniip 2017-02-28 14:08:00
"Conversions from binary to a power-of-2 radix use a simple and fast O(N) bit extraction algorithm."
EvanR 2017-02-28 14:08:44
honestly rendering as base 16 or base 10 is pretty much equal effort on the haskell side
EvanR 2017-02-28 14:09:22
:t showIntAtBase
lambdabot 2017-02-28 14:09:24
(Show a, Integral a) => a -> (Int -> Char) -> a -> ShowS
EvanR 2017-02-28 14:10:27
> showIntAtBase 16 intToDigit 1234
lambdabot 2017-02-28 14:10:30
<[Char] -> [Char]>
EvanR 2017-02-28 14:10:44
> showIntAtBase 16 intToDigit 1234 ""
lambdabot 2017-02-28 14:10:47
"4d2"
mniip 2017-02-28 14:11:16
foreign import ccall mpn_get_str "gmp.h mpn_get_str" :: CString -> CInt -> ByteArray# -> GmpSize#
mniip 2017-02-28 14:11:39
:p
Forkk 2017-02-28 14:12:33
{#call mpn_get_str#}
Forkk 2017-02-28 14:14:56
what is mpn, all I see in the docs is mpz
mniip 2017-02-28 14:15:17
https://gmplib.org/manual/Low_002dlevel-Functions.html
Forkk 2017-02-28 14:15:38
oh I see
mniip 2017-02-28 14:30:49
wait, is the (# State# a, b #) return convention the same as just 'b' ?
hpc 2017-02-28 14:33:24
i suggest reading the (non-haddock) comments around the definition of IO
hpc 2017-02-28 14:34:04
it touches a bit on that, and leads to an amusing conclusion (that is perhaps obvious in retrospect if you consider the existence of unsafePerformIO)
mniip 2017-02-28 14:38:42
hpc, which module is it defined in?
mniip 2017-02-28 14:39:28
ah GHC.Types
mniip 2017-02-28 14:40:01
hpc, there aren't many comments there
mniip 2017-02-28 14:40:05
nothing seems relevant
Ptival 2017-02-28 14:41:13
is there something like (<*>) for when the right thing has to be `pure`d?
mniip 2017-02-28 14:41:38
fmap?
mniip 2017-02-28 14:41:44
aka <$>
mniip 2017-02-28 14:41:53
oh the RIGHT thing
mniip 2017-02-28 14:41:59
<&>
Ptival 2017-02-28 14:43:05
mniip: where is that from?
mniip 2017-02-28 14:43:09
oops
mniip 2017-02-28 14:43:16
it's not defined in any common packages
Ptival 2017-02-28 14:43:27
I guess I can define it locally :)
mniip 2017-02-28 14:43:28
yeah you're out of luck