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