Search Haskell Channel Logs

Sunday, February 19, 2017

#haskell channel featuring c_wraith, prohobo, Akii, johnw, t4nk195, lyxia, and 6 others.

Akii 2017-02-19 06:49:31
lyxia: this is a mind game
Akii 2017-02-19 06:49:50
if that's not a functor, can I come up with a way such that you'd never come up with a functor for it
Akii 2017-02-19 06:50:55
this is the data type I'm trying to do something with http://lpaste.net/352722
johnw 2017-02-19 06:51:32
Akii: every lawful implementation of Monad provides the functionality needed to implement Functor: fmap f x = x >>= return . f
Akii 2017-02-19 06:51:35
this is basically a state monad but with a custom way of combining
Cale 2017-02-19 06:52:08
Akii: That won't be a functor because of the type of aggApply
monochrom 2017-02-19 06:52:34
"a -> ev -> m a" This part may prevent you from having a functor.
Akii 2017-02-19 06:52:38
aggApply is actually the "bind"
Akii 2017-02-19 06:52:43
hard to explain
c_wraith 2017-02-19 06:52:46
heh. Cale and monochrome beat me to it
Akii 2017-02-19 06:52:52
this is what needs to happen during bind
c_wraith 2017-02-19 06:52:53
But yeah, that can't be a Functor
c_wraith 2017-02-19 06:53:18
*monochrom. Sorry, I am typing-challenged this morning
monochrom 2017-02-19 06:53:44
Don't worry, I dropped the e for EFNet's 9-letter restriction anyway :)
c_wraith 2017-02-19 06:54:07
Akii: aggApply has the a type variable in both positive and negative positions. That prevents it from being a Functor.
Tuplanolla 2017-02-19 06:54:33
Shouldn't `(a -> ev) -> m a` work though?
Tuplanolla 2017-02-19 06:55:04
I was wondering if `DeriveFunctor` could handle that.
Akii 2017-02-19 06:55:07
that would not make sense
Akii 2017-02-19 06:55:36
I've to go back and think about it some more
Cale 2017-02-19 06:55:41
Tuplanolla: Yeah, that'd be okay
Akii 2017-02-19 06:56:13
so the background is following: in event sourcing you "emit" events and that mutates some state
Akii 2017-02-19 06:56:23
and I already have a way of doing that, the state monad
Akii 2017-02-19 06:56:30
what I lose though, is composition
Akii 2017-02-19 06:57:05
so I cannot combine 2 emit things because I need to change the state as the events are emitted
Cale 2017-02-19 06:57:41
Akii: Not sure I understand that
Akii 2017-02-19 06:57:56
need to come up with an example
Cale 2017-02-19 06:57:56
Akii: Why isn't that just running one emit after the other?
Akii 2017-02-19 07:02:39
Cale: http://lpaste.net/352723
Akii 2017-02-19 07:02:43
I hope this is enough
Akii 2017-02-19 07:03:06
this is what I have
Akii 2017-02-19 07:03:09
it works
Akii 2017-02-19 07:03:25
unless you start to compose them (doStuff, doOtherStuff)
Akii 2017-02-19 07:03:33
that is because the state (Server) is not updated on the fly
Akii 2017-02-19 07:03:45
updating should be done by raising events
Akii 2017-02-19 07:04:29
right now it's already working; I could run this separately, get out the state and do the apply elsewhere
Akii 2017-02-19 07:04:42
but it really feels like something bind could do for me
johnw 2017-02-19 07:05:21
you could rewrite that transformer stack, to: ReaderT d (StateT [ev] (ExceptT err IO)) a
Akii 2017-02-19 07:06:58
(amended it to actually throw an error)
Akii 2017-02-19 07:09:35
I've to think about this more; pretty sure it's the right direction though
siddhu_ 2017-02-19 07:12:05
I'm trying to write a type that could be either Word8 or Word16. I won't know for sure until runtime, but it will only be one of the two.
siddhu_ 2017-02-19 07:12:12
What's the best way to encode such a type?
lyxia 2017-02-19 07:13:48
Either Word8 Word16
siddhu_ 2017-02-19 07:14:15
And if I also need Word32?
johnw 2017-02-19 07:14:59
siddhu_: you'll need to use a typeclass, probably the SPECIALIZE keyword, and then start your program with an if-test series that calls the typeclass method with the proper type
johnw 2017-02-19 07:15:17
this will compile into your program the same code xN, where N is the number of Word types you expect to support
johnw 2017-02-19 07:15:26
but it has the advantage that you can get optimized code for each type
johnw 2017-02-19 07:15:38
and you only have to write the code itself once
johnw 2017-02-19 07:15:50
this is called "partial evaluation"
siddhu_ 2017-02-19 07:16:39
johnw: cool! Wasn't aware we could do partial evaluation in Haskell. Will take a look.
johnw 2017-02-19 07:16:54
you can do some partial evaluation with type classes, since it specializes the code at compilation time
siddhu_ 2017-02-19 07:17:07
And this also allows me to derive Num instances for the Word types, correct?
johnw 2017-02-19 07:17:08
you still can't partially evaluate on values, though, just types
johnw 2017-02-19 07:17:19
Word type should already have Num instances
johnw 2017-02-19 07:17:24
from Data.Word
siddhu_ 2017-02-19 07:18:49
got it. Will try it out. Thanks!
srbaker 2017-02-19 07:23:01
Heya folks.
prohobo 2017-02-19 07:24:13
no u
srbaker 2017-02-19 07:24:38
I am curious about "runtime dispatch". I want to have a map of regular expressions to functions, and call a function based on matching that Regex.
srbaker 2017-02-19 07:24:56
Is there something like multi-dispatch that supports regex as the matcher?
srbaker 2017-02-19 07:25:01
Am I completely nuts?
srbaker 2017-02-19 07:26:07
Sorry, I think I just answered my own question when writing it here.
monochrom 2017-02-19 07:26:40
I would translate the regexes into automata, and have their final states indicate which function to call.
srbaker 2017-02-19 07:26:53
Interesting.
monochrom 2017-02-19 07:28:48
I go the automaton way because there is a way you can combine these automata into one giant automaton, so you are matching against multiple regexes in one go.
srbaker 2017-02-19 07:29:36
Thanks, I will read up on that.
t4nk195 2017-02-19 07:33:09
Hello, friends! Why this doesn't work as a fibonacci sequence? It seems I don't understand pattern mathing like I though I did
t4nk195 2017-02-19 07:33:11
let {listGen t@(_:x@(_:_)) = (sum x):listGen t} in take 10 $ listGen [1,2]
monochrom 2017-02-19 07:37:21
OK, so you're saying listGen (1:2:[]) = sum (2:[]) : listGen (1:2:[])
t4nk195 2017-02-19 07:39:19
Hmm, but i'm telling to take last two elements in list and sum them, why sum(2:[]) ?
t4nk195 2017-02-19 07:39:36
I see that it's what haskell evaluates, but why?
t4nk195 2017-02-19 07:39:55
i'm pattern matching last two numbers, ain't I?
monochrom 2017-02-19 07:40:01
No.
Cale 2017-02-19 07:40:23
x is the tail of whatever list you're passing in
Cale 2017-02-19 07:40:29
and t is the whole list
monochrom 2017-02-19 07:40:41
match 1:(2:[]) against t@(_:x@(_:_))
Cale 2017-02-19 07:40:44
So if you give [1,2], then t = [1,2] and x = [2]
monochrom 2017-02-19 07:41:55
Another exercise: Match a:(b:(c:(d:[]))) against t@(_:x@(_:_))
t4nk195 2017-02-19 07:42:53
Hmm
bollu 2017-02-19 07:43:05
Cale, monochrom: what are some "nice" Kan extensions? examples that I can think of are things like extending a function defined on a basis to the larger space, but I'm not sure if this is a "legit" Kan extension
t4nk195 2017-02-19 07:43:18
I think I'm beginning to understand...