noan 2017-02-07 03:45:09
merijn, is that the name of the spec?
Profpatsch 2017-02-07 03:45:11
quchen: Yes, but it's another concept one has to learn.
quchen 2017-02-07 03:45:19
merijn: That's what I said. There was no comma missing.
noan 2017-02-07 03:45:21
laziness is fine and doesn't trouble me
merijn 2017-02-07 03:45:31
noan: https://www.haskell.org/onlinereport/haskell2010/
thatguy 2017-02-07 03:45:35
dramforever: so my function which I pass to foldr should just return the same thing forever once the condition has been reached?
dramforever 2017-02-07 03:45:35
I doubt if you'll make it...
thatguy 2017-02-07 03:45:56
noan: I am learning haskell with http://www.cis.upenn.edu/~cis194/spring13/lectures.html it has a lot of exercises and is pretty concise, I like it very much
dramforever 2017-02-07 03:46:01
thatguy: just remember one thing, there isn't really a thing called 'terminating condition'
quchen 2017-02-07 03:46:02
The Report is a great beginner learning resource, provided you are already proficient in Haskell.
dramforever 2017-02-07 03:46:15
because there's no sequence there
Profpatsch 2017-02-07 03:46:27
merijn: quchen Took me a second to understand that sentence as well. Commas are hard. :)
merijn 2017-02-07 03:46:41
quchen: Also for some types of imperative programmers
dramforever 2017-02-07 03:46:48
hmm
noan 2017-02-07 03:46:52
thatguy, I worked with that a while back but found it had a gross gap in information personally
Profpatsch 2017-02-07 03:46:52
Especially when most people leave them out and your brain automatically insert them.
Profpatsch 2017-02-07 03:47:03
*inserts
merijn 2017-02-07 03:47:08
quchen: People who are used to C/C++ insanity to the point of reading those specs the Haskell spec is pretty light reading :)
noan 2017-02-07 03:47:28
I'm curious about this though. With regard to laziness.. Where is it that people typically trip up?
noan 2017-02-07 03:47:36
It seems perfectly reasonable to me
thatguy 2017-02-07 03:47:38
noan: yeah I know what you mean, you learn most while doing the exercises not while reading the book, it doesn't ellaborate much
AndreasK 2017-02-07 03:48:22
noan: Causes spaceleaks and unexpected performance characteristics at times
Profpatsch 2017-02-07 03:48:27
noan: Most people I know who don't like laziness argue that you can't know what happens.
thatguy 2017-02-07 03:48:33
dramforever: I am not sure I get what you mean, but I'll try to do it with foldr
Profpatsch 2017-02-07 03:48:58
And that's true if you come from a (light) C background.
Profpatsch 2017-02-07 03:49:02
Or maybe Perl.
dramforever 2017-02-07 03:49:06
you know what
dramforever 2017-02-07 03:49:18
thatguy: search for "findKey key =" in http://learnyouahaskell.com/modules#data-list
noan 2017-02-07 03:49:30
Profpatsch, why on earth would I need to know what happens at a machine level? I'm not programming microcontrollers here.
dramforever 2017-02-07 03:49:35
you'll see a 'terminating' foldr
quchen 2017-02-07 03:49:45
> foldr const 0 [1..]
lambdabot 2017-02-07 03:49:47
1
Profpatsch 2017-02-07 03:49:51
But I'd argue the garbage collector weighs harder there.
noan 2017-02-07 03:49:58
I don't want to know what's happening at machine level. That means throwing away WAY too much abstraction
dramforever 2017-02-07 03:49:59
quchen: that's too trivial
quchen 2017-02-07 03:50:04
> foldr const 0 [2..]
lambdabot 2017-02-07 03:50:06
2
dramforever 2017-02-07 03:50:16
quchen: stop that
Profpatsch 2017-02-07 03:50:27
noan: Just promise me you won't try hard realtime programming in Haskell :P
noan 2017-02-07 03:50:43
Profpatsch, define that term.
merijn 2017-02-07 03:50:52
noan: Well at some point it helps to know what's going on, but only selectively
dramforever 2017-02-07 03:51:00
noan: I believe that concepts and practices are different enough that you'd better start from the basics
quchen 2017-02-07 03:51:07
:t \p -> foldr (\x rest -> if p x then rest else x:rest) [] -- filter – less trivial?
lambdabot 2017-02-07 03:51:09
Foldable t => (a -> Bool) -> t a -> [a]
c_wraith 2017-02-07 03:51:18
noan: hard realtime programs have fixed deadlines that they must perform actions by. If they don't, it's considered a hard failure.
merijn 2017-02-07 03:51:26
noan: "hard realtime" is when there are 1) deadlines (usually rather short ones) and 2) missing a deadline is considered complete system failure
quchen 2017-02-07 03:51:36
e.g. radio transmitters.
noan 2017-02-07 03:51:40
aaah
dramforever 2017-02-07 03:51:42
If that 'just need syntax reference' thing worked going from C# -> Ruby that's *not*, *NOT* going to work with Haskell
quchen 2017-02-07 03:51:50
Not hard real time: most things.
dramforever 2017-02-07 03:51:53
definitely not
noan 2017-02-07 03:51:57
That's the sort of thing I was referring to when I said "I'm not programming microcontrollers here"
merijn 2017-02-07 03:51:58
noan: As opposed to soft realtime when X% of deadlines can be missed without considering it complete system failure
dramforever 2017-02-07 03:52:01
not, not, not, not working
noan 2017-02-07 03:52:07
aka HIGHLY performance dependant and specific applications.
dramforever 2017-02-07 03:52:07
I think that's probably enough
AndreasK 2017-02-07 03:52:07
Lazyness sometimes leads to unexpected space leaks, unexpected performance characteristics can also happen but so far i didn't hit that often
Profpatsch 2017-02-07 03:52:09
At least soft realtime processing is the reason why the golang GC is "optimized" the way it is.
merijn 2017-02-07 03:52:38
noan: Soft realtime would be things like audio/video/games where dropping a frame once in a while is considered ok
noan 2017-02-07 03:52:44
makes sense though, and yeah, I would likely use something a lot closer to metal for those things.
Profpatsch 2017-02-07 03:53:12
Like a GL library that has a nice Haskell wrapper. ;P
noan 2017-02-07 03:53:16
Thanks, I hadn't heard that term before. I've been out of the loop for a couple years not really programming, and was doing web stuff before then
dramforever 2017-02-07 03:53:17
noan: Let's have an example, perhaps
noan 2017-02-07 03:53:41
noan, of something closer to metal if I wanted to program for instance a radio transmitter?
dramforever 2017-02-07 03:53:51
Hmm, Actually I wonder if Scala would have helped you getting into Haskell
Profpatsch 2017-02-07 03:53:51
Then again, lots of people doing hard numeric in Python.
noan 2017-02-07 03:53:55
Probably C or Rust.
noan 2017-02-07 03:54:19
dramforever, It has. I have a basic understanding of the idea of a typeclass and stuff like that
dramforever 2017-02-07 03:54:27
hmm
noan 2017-02-07 03:54:45
here... lets give context of where I'm struggling...
dramforever 2017-02-07 03:54:56
I just, you know it just sort of never worked before
noan 2017-02-07 03:55:12
https://github.com/AlexaDeWit/haskellsandboxserver/blob/master/src/db/queries/User.hs
noan 2017-02-07 03:55:25
I am currently attempting to accomplish something akin to this..
dramforever 2017-02-07 03:55:32
and people end up like throwing 'do' everywhere and don't get how to do IO at all or something
noan 2017-02-07 03:55:33
(this is my currently broken code=
noan 2017-02-07 03:56:28
I think one big barrier I'm having is I don't understand that App type very well, which is from Matt Parson's work here: https://github.com/parsonsmatt/servant-persistent/blob/master/src/Config.hs
AndreasK 2017-02-07 03:57:18
Profpatsch: afaik numerical programming in python falls back to calling c for almost anything performance sensitive though
noan 2017-02-07 03:57:26
I currently think of IO as an analogue to Scalaz's Task type. Representing some side-effecting code to be executed later.
dibblego 2017-02-07 03:57:51
Task is full of bugs, and generally does not work. This is not true of IO :)
dramforever 2017-02-07 03:57:53
You know what a monad is?
noan 2017-02-07 03:58:06
dibblego, dachshund <3
Profpatsch 2017-02-07 03:58:08
AndreasK: Yeah of course.
noan 2017-02-07 03:58:11
dramforever, yes.
dramforever 2017-02-07 03:58:16
If I tell you line 21 is wrong, do you notice something?
dibblego 2017-02-07 03:58:17
rottweiler
noan 2017-02-07 03:58:20
although I forgot the endofunctor laws
Profpatsch 2017-02-07 03:58:32
But contrary to python we can actually get bare-metall-y fast with pure Haskel.l
Profpatsch 2017-02-07 03:58:38
So that's that.
dramforever 2017-02-07 03:58:47
that's for hard mathematics that programmers need only a feeling of
noan 2017-02-07 03:58:49
http://www.dogbreedplus.com/dog_breeds/images/rottweiler-puppy-2.jpg
sm 2017-02-07 03:58:51
g'day all. ircbrowse.net is down, anyone we can ping here ?
dibblego 2017-02-07 03:59:14
sm: I believe (not 100%) it is chrisdone
sm 2017-02-07 03:59:37
I don't think he is here alas
dramforever 2017-02-07 04:00:13
noan: line 21 and 24 are wrong and I think it's because you don't know what *the* monad does
dramforever 2017-02-07 04:00:45
oh uh...
noan 2017-02-07 04:01:11
dramforever, Oh, a lot of it is wrong. Mostly I wanted to show the type signature I was thinking I would like to have, and the repo for the dependant types involved.
noan 2017-02-07 04:01:24
That function is a god damn mess and will be thrown in the bin
dramforever 2017-02-07 04:01:45
oh
noan 2017-02-07 04:02:08
There's a lot of standard haskell I don't yet understand. And type signatures alone only convey so much
thatguy 2017-02-07 04:02:09
I don't get why foldr const 0 [1..] returns 1. As I understood it, the first call will be const 1 0 which returns 1, the second call will be const 2 1, which should return 2 and so on...what am I missunderstanding?
dramforever 2017-02-07 04:02:12
I see you've now at least half-baked your manmonadship :)
thatguy 2017-02-07 04:02:14
>foldr const 0 [1..]
thatguy 2017-02-07 04:02:33
> foldr const 0 [1..]
lambdabot 2017-02-07 04:02:35
1
dramforever 2017-02-07 04:02:39
thatguy: it's 'const 0 (...)' and the rest don't matter
dramforever 2017-02-07 04:02:51
thatguy: it's 'const 1 (...)' and the rest don't matter
dramforever 2017-02-07 04:03:23
The *last* call will be 'const ??? 0' but there's no such last call
thatguy 2017-02-07 04:03:36
ahh ok
thatguy 2017-02-07 04:03:44
yeah I need to look up the implementation again
thatguy 2017-02-07 04:04:05
I think I had a wrong model of that function in my head which worked until now
thatguy 2017-02-07 04:04:07
dramforever: thanks
noan 2017-02-07 04:04:23
dramforever, got a moment to walk me through what App is here in terms of Haskell syntax? https://github.com/AlexaDeWit/haskellsandboxserver/blob/master/src/db/Config.hs
noan 2017-02-07 04:04:45
I get the deriving part, that's just typeclass membership
dramforever 2017-02-07 04:05:03
uh, you sure you do?
dramforever 2017-02-07 04:05:15
Tell me how they work
merijn 2017-02-07 04:05:19
noan: What syntax don't you understand?
dramforever 2017-02-07 04:05:23
say, just the Functor part
noan 2017-02-07 04:05:26
{ runApp :: ReaderT Config (ExceptT ServantErr IO) a
dramforever 2017-02-07 04:05:38
That's called record syntax
noan 2017-02-07 04:05:48
dramforever, I didn't mean to say I understood all the typeclasses. Just that it was a member of them
merijn 2017-02-07 04:05:49
I suspect he's not familiar with record syntax :p
noan 2017-02-07 04:05:57
and as such I can walk myself through each typeclass in turn
dramforever 2017-02-07 04:06:04
noan: well what does being a member mean?
merijn 2017-02-07 04:06:56
noan: "data Foo = Bar { myId :: Int, blah :: String, quux :: Bool }" defines a "Bar" constructors with an Int, String and Bool field. The record syntax just generate some convenient named fields for interacting with those fields
noan 2017-02-07 04:07:00
in haskell terms, I'm not sure how it's worded. In Scala it means that for each type class it is a member of there exists an instance of that typeclass for that class, which provides all the functions defined for that type class.
dramforever 2017-02-07 04:07:09
(Disclaimer: I'm not walking you through this. I believe with good faith that you don't know enough to get started, so I'm walking you to the beginner tutorial)
dramforever 2017-02-07 04:07:27
But I *will* explains things as best as I could
dramforever 2017-02-07 04:07:39
noan: That's quite right
dramforever 2017-02-07 04:07:51
but where are the functions for Functor defined?
dramforever 2017-02-07 04:08:15
The definitions are nowhere to be found
noan 2017-02-07 04:08:39
my expectation here is that somehow within the haskell type system it is able to use instances from magically elsewhere, which is admittedly part of the frustration
noan 2017-02-07 04:09:00
as if haskell provides somehow a "standard" depending on how you define your new type
dramforever 2017-02-07 04:09:05
Yes!
dramforever 2017-02-07 04:09:28
How? It's actually compiler magic here!
dibblego 2017-02-07 04:09:29
noan: Haskell uses a different mechanism to Scala, but for the same idea. Scala also a) allows abuse of this mechanism b) has a highly populated cottage industry of this abuse so as to make differentiation difficult
dramforever 2017-02-07 04:09:33
'GeneralizedNewtypeDeriving'
noan 2017-02-07 04:09:49
because in scala you bet your ass I'd be providing a implicit object Monad[App[T]] which provides... oh fuck what is it in scalaz? id and flatMap?
dibblego 2017-02-07 04:09:50
class Functor f where fmap :: (a -> b) -> f a -> f b
dramforever 2017-02-07 04:10:05
Enough for that, let's get the newtype part right first
noan 2017-02-07 04:10:10
dibblego, I know, I know.
dibblego 2017-02-07 04:10:11
trait Functor[F[_]] { def fmap[A, B](f: A => B): F[A] => F[B] {
dramforever 2017-02-07 04:10:27
What's a 'newtype'? Well, do you know what's a 'data'?
dibblego 2017-02-07 04:10:34
noan: scalaz does not repeat some of the historical mistakes of haskell
dibblego 2017-02-07 04:10:54
newtype is what scala tries to implement with value types, but fails [again]
noan 2017-02-07 04:10:54
a data is just what I would think of as a type with a default constructor? something which can contain data.
noan 2017-02-07 04:11:01
I don't want to compare it to a struct
noan 2017-02-07 04:11:06
since it could be a sum or product type
dramforever 2017-02-07 04:11:17
I heard there's a thing called a 'case class' in scala
dramforever 2017-02-07 04:11:27
but a 'data' is non-extendable
dibblego 2017-02-07 04:11:35
noan: I haven't been following properly, so not sure on where the issue is, just saying facts in the hope one helps :)
noan 2017-02-07 04:11:40
a scala case class is a product type.
dramforever 2017-02-07 04:11:41
You define it to have 7 constructors, it has 7 constructors everywhere
dramforever 2017-02-07 04:11:55
noan: but they often extend a common class right?
dibblego 2017-02-07 04:11:59
scala implements sum types using sealed trait
dibblego 2017-02-07 04:12:09
dramforever: No.
dramforever 2017-02-07 04:12:16
dibblego: oh
dramforever 2017-02-07 04:12:18
they do
dramforever 2017-02-07 04:12:20
Sorry
merijn 2017-02-07 04:12:22
dibblego: Can you elaborate what the historical mistakes of Haskell's newtype are?
dramforever 2017-02-07 04:12:24
I don't really know scala
noan 2017-02-07 04:12:34
don't stress yourself over analogues
dibblego 2017-02-07 04:12:48
merijn: none, I meant in library design, Scala does not improve on anything over Haskell wh en it comes to language design
dramforever 2017-02-07 04:12:51
noan: so somehow None and Some[A] are both Option[A] right?
noan 2017-02-07 04:12:52
You can use proper terms and I will either look them up, know them, or seek to learn them
merijn 2017-02-07 04:12:56
dibblego: oh, right
dibblego 2017-02-07 04:13:15
noan: then what is the query>
dibblego 2017-02-07 04:13:16
?
noan 2017-02-07 04:13:21
dramforever, I haven't really written scala in like 2 years, but it's something like that
dramforever 2017-02-07 04:13:24
ok, I was trying to make an analogy
dramforever 2017-02-07 04:13:27
sorry about the confusion
dramforever 2017-02-07 04:13:32
okay no more scala
noan 2017-02-07 04:13:36
dibblego, at present, helping me understand https://github.com/AlexaDeWit/haskellsandboxserver/blob/master/src/db/Config.hs line 54
dibblego 2017-02-07 04:14:00
be advised, I have typed with 9 fingers since 1996, and from today I have only 6
dramforever 2017-02-07 04:14:02
dibblego: This is going to take forever, what do you think?
noan 2017-02-07 04:14:08
sealed trait Option[+E]
noan 2017-02-07 04:14:08
case class Some[+E]( element : E ) extends Option[E]
noan 2017-02-07 04:14:08
case object None extends Option[Nothing]
noan 2017-02-07 04:14:12
Is what it basically is iirc
dramforever 2017-02-07 04:14:13
ooh
dramforever 2017-02-07 04:14:15
nice
dibblego 2017-02-07 04:14:20
dramforever: we'll be right
noan 2017-02-07 04:14:28
None is a singleton for which there exists one instance.
noan 2017-02-07 04:14:36
and only ever one
dramforever 2017-02-07 04:14:49
Nothing is a type that extends every single type right?
dibblego 2017-02-07 04:14:56
noan: there is no close analogue to that in haskell
noan 2017-02-07 04:15:20
dibblego, True? False?
dibblego 2017-02-07 04:15:20
sealed trait Option[E]
dramforever 2017-02-07 04:15:22
yes because Haskell uses the easier notion of sum and produc types
dramforever 2017-02-07 04:15:34
data Option a = Some a | None
dibblego 2017-02-07 04:15:40
case class Some[E](element: E) extends Option[E]
dibblego 2017-02-07 04:15:47
case class None[E]() extends Option[E]
dibblego 2017-02-07 04:15:50
that is closer to haskell
dibblego 2017-02-07 04:16:01
noan: yes, true, for scala
dramforever 2017-02-07 04:16:04
dibblego: Thank you for helping me with scala
dramforever 2017-02-07 04:16:12
Let's move on
dibblego 2017-02-07 04:16:24
believe me, I've moved on from scala :)
dramforever 2017-02-07 04:16:32
So what's that { x :: y } thing?
noan 2017-02-07 04:16:35
dibblego, I was thinking you were talking about singleton objects with one instance. Hence why I was thinking of things like.. Nothing True False etc.
dibblego 2017-02-07 04:16:36
waste of human
dibblego 2017-02-07 04:16:45
noan: data () = ()
noan 2017-02-07 04:16:51
that too.
dibblego 2017-02-07 04:16:57
there is no nominal subtyping and subsequent variance, in haskell
dibblego 2017-02-07 04:17:18
dramforever: cons is :: in scala, don't know what you mean otherwise
Xnuk 2017-02-07 04:17:24
@let data A = A { foo :: Int }
lambdabot 2017-02-07 04:17:26
Defined.
noan 2017-02-07 04:17:29
so.. newtype App a... is a polymorphic type, right?
dramforever 2017-02-07 04:17:33
https://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-700004.2.1
noan 2017-02-07 04:17:37
like App[T]
dramforever 2017-02-07 04:17:39
There you go
dibblego 2017-02-07 04:17:46
noan: yes, since (a) is lower-case it is declared forall, similar in scala to [A]
dramforever 2017-02-07 04:17:48
dibblego: I was refering to the record syntax
dibblego 2017-02-07 04:17:58
scala has record syntax, but it's shit
merijn 2017-02-07 04:18:09
dibblego: So...like haskell then? ;)
noan 2017-02-07 04:18:17
ooooh
dibblego 2017-02-07 04:18:19
yes, pretty much
dramforever 2017-02-07 04:18:22
Haskell's record syntax isn't like it really works or anything
noan 2017-02-07 04:18:22
I got a little lost in the noise
dramforever 2017-02-07 04:18:32
https://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-700004.2.1
noan 2017-02-07 04:18:33
it's analogous to it being a Data thing?
Logio 2017-02-07 04:18:43
noan: yes, but with only a single constructor
merijn 2017-02-07 04:18:51
dramforever: I don't like haskell records, but then I'm not sure how to make them better either :\
merijn 2017-02-07 04:19:00
Syntax is hard!
dibblego 2017-02-07 04:19:02
noan: if you replace newtype with data, on line 54, not much will change and it is best to ignore that which will change, for now only
dramforever 2017-02-07 04:19:08
Because it's a raw, compile-time only wrapper around the inner type
dramforever 2017-02-07 04:19:20
It's easier to work with sometimes
noan 2017-02-07 04:19:27
if it's defined for all a, how can it have the type runApp :: ReaderT Config (ExceptT ServantErr IO)
dramforever 2017-02-07 04:19:50
Because it's *not*
dibblego 2017-02-07 04:19:55
noan: the analogue to newtype, for scala, is value types, where an optimisation under certain restrictions can be applied [scala messes it up badly though]
dramforever 2017-02-07 04:20:05
It has type runApp :: App a -> ReaderT Config (ExceptT ServantErr IO) a
noan 2017-02-07 04:20:21
ooooooh
dramforever 2017-02-07 04:20:23
According to the Haskell Report section I linked
dibblego 2017-02-07 04:20:37
case class App[A](runApp :: ReaderT[Config, ExceptT[ServantErr, IO], A]) // there is no deriving
dramforever 2017-02-07 04:20:51
That one is just newtype App a = App (ReaderT Config (ExceptT ServantErr IO) a)
dramforever 2017-02-07 04:20:56
with extra goodies
jchia_ 2017-02-07 04:20:57
Which container gives me good performance if I only need to prepend/append and get length? Getting the length of a list is linear, correct? Is there a container with O(1) append and O(1) length?
Logio 2017-02-07 04:21:12
noan: without the record syntax, the line would read: newtype App a = App (ReaderT Config (ExceptT ServantErr IO) a)
dibblego 2017-02-07 04:21:14
in haskell, you can use runApp to "get" and "set" the [one and only] field
dibblego 2017-02-07 04:21:28
in scala, you do the same with .runApp and .copy(runApp =
kadoban 2017-02-07 04:21:31
jchia_: Data.Sequence I think has O(1) length, or it's pretty easy to wrap a list with length.
dramforever 2017-02-07 04:21:46
Which is *not* the common use here, when it wraps monads
niklasb 2017-02-07 04:21:53
jchia_: just use two lists plus an int
kadoban 2017-02-07 04:21:55
jchia_: Oh you say you need to prepend and append? Then probably Data.Sequence for sure
Logio 2017-02-07 04:21:58
noan: then you could define runApp separately to unwrap the value from the App constructor
dibblego 2017-02-07 04:22:02
jchia: data DList a = DList (a -> a) has O(1) cons/snoc/append with O(n) on most other operations
jchia_ 2017-02-07 04:22:12
kadoban, niklasb: append or prepend, doesn't matter which
dramforever 2017-02-07 04:22:13
noan: Let's get a simpler example
dramforever 2017-02-07 04:22:21
@undefine
lambdabot 2017-02-07 04:22:21
Undefined.
niklasb 2017-02-07 04:22:22
jchia_: then just ([a], Int)
dramforever 2017-02-07 04:22:27
That cleans the environment
noan 2017-02-07 04:22:35
I know lambdabot
jchia_ 2017-02-07 04:22:37
niklasb OK
noan 2017-02-07 04:22:39
it is/was present in #scala
dramforever 2017-02-07 04:22:44
@let data Point a = Point { px :: a, py :: a }
lambdabot 2017-02-07 04:22:46
Defined.
dramforever 2017-02-07 04:22:56
What can you do? well
dramforever 2017-02-07 04:22:58
:t Point
lambdabot 2017-02-07 04:23:00
a -> a -> Point a
dramforever 2017-02-07 04:23:01
:t px
dramforever 2017-02-07 04:23:02
:t py
dibblego 2017-02-07 04:23:02
noan: haskell does kind inference (scala never does), and type constructors always take one argument, where in scala, yopu have to go through the type-lambda ceremony, or subsequent efforts to mitigate that
lambdabot 2017-02-07 04:23:03
Point a -> a
lambdabot 2017-02-07 04:23:04
Point a -> a
dramforever 2017-02-07 04:23:30
:t px (Point 1 2) -- Let's see an example
lambdabot 2017-02-07 04:23:31
Num a => a
dramforever 2017-02-07 04:23:35
> px (Point 1 2) -- Let's see an example
lambdabot 2017-02-07 04:23:37
1
dramforever 2017-02-07 04:23:50
it gives us the first field
dibblego 2017-02-07 04:24:06
scala> case class Point[A](px: A, py: A)
dibblego 2017-02-07 04:24:12
scala> Point(1, 2).px
dibblego 2017-02-07 04:24:13
res0: Int = 1
dramforever 2017-02-07 04:24:18
which is quite reasonable, given that we defined it with px as the first field
noan 2017-02-07 04:24:44
> px (Point "Foo" "Bar")
lambdabot 2017-02-07 04:24:46
"Foo"
noan 2017-02-07 04:24:54
right okay this explains a lot more.
dibblego 2017-02-07 04:25:04
scala> Point("foo", "bar").px
dibblego 2017-02-07 04:25:04
res2: String = foo
dramforever 2017-02-07 04:25:14
You can also construct these with named fields
noan 2017-02-07 04:25:20
Seeing things in the scala syntax sometimes clears it up a lot
dramforever 2017-02-07 04:25:22
> py (Point { px = 1, py = 2 })
lambdabot 2017-02-07 04:25:26
2
dibblego 2017-02-07 04:25:43
@let data Point a = Point { px :: a, py :: a } deriving Show -- add Show
lambdabot 2017-02-07 04:25:44
.L.hs:160:1: error:
lambdabot 2017-02-07 04:25:44
Multiple declarations of 'Point'
lambdabot 2017-02-07 04:25:44
Declared at: .L.hs:158:1
dibblego 2017-02-07 04:25:52
@let data Point' a = Point' { px :: a, py :: a } deriving Show -- add Show
lambdabot 2017-02-07 04:25:54
.L.hs:160:24: error:
lambdabot 2017-02-07 04:25:54
Multiple declarations of 'px'
lambdabot 2017-02-07 04:25:54
Declared at: .L.hs:158:22
dibblego 2017-02-07 04:25:57
blah
dramforever 2017-02-07 04:25:59
@undefine
lambdabot 2017-02-07 04:25:59
Undefined.
dramforever 2017-02-07 04:26:04
@let data Point a = Point { px :: a, py :: a } deriving Show -- add Show
dibblego 2017-02-07 04:26:05
@let data Point a = Point { px :: a, py :: a } deriving Show -- add Show
lambdabot 2017-02-07 04:26:07
Defined.
dibblego 2017-02-07 04:26:07
lol
dramforever 2017-02-07 04:26:08
lol
lambdabot 2017-02-07 04:26:08
.L.hs:161:1: error:
lambdabot 2017-02-07 04:26:09
Multiple declarations of 'Point'
lambdabot 2017-02-07 04:26:09
Declared at: .L.hs:158:1
noan 2017-02-07 04:26:14
heh
dramforever 2017-02-07 04:26:15
one of us stop...
dramforever 2017-02-07 04:26:26
> Point { px = 1, py = 2 }
dibblego 2017-02-07 04:26:27
> (Point 1 2) { px = 77 }
lambdabot 2017-02-07 04:26:28
Point {px = 1, py = 2}
lambdabot 2017-02-07 04:26:30
Point {px = 77, py = 2}
dibblego 2017-02-07 04:26:40
scala> Point(1, 2).copy(px = 77)
dibblego 2017-02-07 04:26:40
res3: Point[Int] = Point(77,2)
dramforever 2017-02-07 04:26:43
Maybe I stop?
dibblego 2017-02-07 04:26:53
just wanted to show set/copy
dibblego 2017-02-07 04:26:58
that's it, done
dramforever 2017-02-07 04:27:00
> Point { px = 1, py = 2 }
lambdabot 2017-02-07 04:27:05
Point {px = 1, py = 2}
dramforever 2017-02-07 04:27:15
noan: see it's nicely constructed
noan 2017-02-07 04:27:31
yeah
dramforever 2017-02-07 04:27:34
@let myHome = Point { px = 123, py = 234 }
lambdabot 2017-02-07 04:27:35
Defined.
dibblego 2017-02-07 04:27:40
scala> Point(px = 1, py = 2)
dibblego 2017-02-07 04:27:40
res1: Point[Int] = Point(1,2)
dramforever 2017-02-07 04:27:40
You can do record updates
thatguy 2017-02-07 04:27:44
am I right that this application of mapA won't work on infinite lists? http://lpaste.net/352176
dibblego 2017-02-07 04:27:57
scala> Point(py = 1, px = 2)
dibblego 2017-02-07 04:27:57
res2: Point[Int] = Point(2,1)
dramforever 2017-02-07 04:28:00
> myHome { px = 0 } -- move the x coordinates
lambdabot 2017-02-07 04:28:05
Point {px = 0, py = 234}
noan 2017-02-07 04:28:08
dramforever, well, copy operations returning a new copy of the same type
dramforever 2017-02-07 04:28:12
see how it changed
noan 2017-02-07 04:28:16
which is what dibbles shoed if I understand right
dramforever 2017-02-07 04:28:29
I don't know, I can't read Scala
dibblego 2017-02-07 04:28:32
thatguy: it will, why do you think it won't?
noan 2017-02-07 04:28:33
myHome never changed.
dramforever 2017-02-07 04:28:40
> myHome -- you bet
noan 2017-02-07 04:28:41
the value you got after is a new Point.
lambdabot 2017-02-07 04:28:43
Point {px = 123, py = 234}
dibblego 2017-02-07 04:28:43
yes, .copy does update in scala
dramforever 2017-02-07 04:29:05
which is right everywhere in Haskell
dibblego 2017-02-07 04:29:21
scala equals haskell at one thing, the most annoying part of haskell, this is quite funny
dramforever 2017-02-07 04:29:25
(Exceptions are not interesting at all, in case anyone wants to be pedantic)
noan 2017-02-07 04:29:28
indeed, I just wanted to be clear that we weren't doing any "changing"
dramforever 2017-02-07 04:29:38
yes
dramforever 2017-02-07 04:29:47
review
dramforever 2017-02-07 04:29:48
:t Point
lambdabot 2017-02-07 04:29:50
a -> a -> Point a
dibblego 2017-02-07 04:29:52
there is no changing in haskell, because haskell, and no changing in scala, if you are a moral person
dramforever 2017-02-07 04:29:52
:t px
lambdabot 2017-02-07 04:29:54
Point a -> a
merijn 2017-02-07 04:29:56
thatguy: Well, define "work" :)
dramforever 2017-02-07 04:30:25
constructor makes a value, record selector gets values out of them
thatguy 2017-02-07 04:30:25
merijn: it wouldn't terminate :P
merijn 2017-02-07 04:30:42
thatguy: It won't terminate and, presumably, crash because it ran out of memory at some point
thatguy 2017-02-07 04:30:43
i.e. it would work quite a lot actually
dramforever 2017-02-07 04:30:46
noan: and now we have: newtype App a = App (Voodoo a)
thatguy 2017-02-07 04:30:46
:D
dramforever 2017-02-07 04:31:21
Where I shall let 'Voodoo' stand for 'ReaderT Config (ExceptT ServantErr IO)'
thatguy 2017-02-07 04:31:26
merijn: would you know a better way to implement that function which works on infinite lists?
dibblego 2017-02-07 04:31:27
thatguy: sorry, you are right
merijn 2017-02-07 04:31:57
thatguy: Well, not as-is
dramforever 2017-02-07 04:32:02
now with records, we understand what this means: newtype App a = App { runApp :: Voodoo a }
thatguy 2017-02-07 04:32:03
dibblego: I think you got the wrong person
merijn 2017-02-07 04:32:09
thatguy: But presumably you don't care about the result list if it's infinite?
dramforever 2017-02-07 04:32:21
it gives 'App :: Voodoo a -> App a', and 'runApp :: App a -> Voodoo a'
dibblego 2017-02-07 04:32:29
thatguy: no, I said earlier it will, that is a mistake, I missed a bit of the code
dramforever 2017-02-07 04:32:37
noan: 'App a' itself? Just a wrapper to let us better track of it
dramforever 2017-02-07 04:32:43
*keep better track
Xnuk 2017-02-07 04:32:57
> let mapA fun = foldr (liftA2 (:).fun) (pure []) in mapA Just [1..]
merijn 2017-02-07 04:32:58
thatguy: :et
lambdabot 2017-02-07 04:32:59
*Exception: stack overflow
Xnuk 2017-02-07 04:33:04
> let mapA fun = foldr (liftA2 (:).fun) (pure []) in mapA (const Nothing) [1..]
lambdabot 2017-02-07 04:33:07
Nothing
merijn 2017-02-07 04:33:12
thatguy: Let's start from something else, what do you actually wanna do?
noan 2017-02-07 04:33:14
ah hah. So anything that is a Voodoo a I should be able to wrap freely... and anything that is an App a should be unwrappable with runApp?
dramforever 2017-02-07 04:33:14
So we've went such length just to get a... wrapper
dramforever 2017-02-07 04:33:26
Sure we've learned more about records
dramforever 2017-02-07 04:33:31
noan: That's right
dibblego 2017-02-07 04:33:41
noan: correct, just like in scala
noan 2017-02-07 04:33:45
the part that had me all fucky is I couldn't understand the wrapping part
noan 2017-02-07 04:33:50
especially
noan 2017-02-07 04:34:04
well, I guess it's just a constructor like Point
dramforever 2017-02-07 04:34:05
And the meaning itself is pretty simple
noan 2017-02-07 04:34:08
so the wrapping is super easy
thatguy 2017-02-07 04:34:10
merijn: accomplish a task in CIS 194, they said in the tutorial you should try to implement that function and I did it that way, now I have a different task and find doing myself something similar (I want to run a lot of parsers after each other and "terminate" when the one of them returns nothing)
thatguy 2017-02-07 04:34:15
and return the result I got until then
dramforever 2017-02-07 04:35:08
noan: so.. end of this 'walkthrough'?
thatguy 2017-02-07 04:35:10
merijn: wouldn't there be a way to implement this mapA s.t. stuff like take 20 resultList works even if I passed in an infinite list
noan 2017-02-07 04:35:36
a much better understanding of what you referred to as "record syntax"
merijn 2017-02-07 04:35:54
thatguy: Not directly, you might wanna have a look at the monad-loops package
thatguy 2017-02-07 04:36:38
merijn: I am not at monads yet
noan 2017-02-07 04:36:49
so lets take it one step closer on a related sort of thing for instance
thatguy 2017-02-07 04:36:57
but if that is a hard task and I am not just to stupid to find the answer I'm okay with that for now
dramforever 2017-02-07 04:37:08
still there :)
noan 2017-02-07 04:37:17
if I have... App (Key User) as a type... syntactically that's essentially an App a where the a is Key b where b is User?
noan 2017-02-07 04:37:24
a Foo of a Bar of a Baz?
dramforever 2017-02-07 04:37:25
yep
dramforever 2017-02-07 04:37:44
Apparently the basics of types of Scala is sane :)
noan 2017-02-07 04:37:46
kay, wanted to make sure that wasn't a tuple. Tuple notation would be ,
noan 2017-02-07 04:37:52
dramforever, HAH
Sheo 2017-02-07 04:37:54
Hey! Does anyone know about compiler steps. GHC wiki says src->Core->STG->c-- . But c-- has some outdated marks on the page.
noan 2017-02-07 04:38:08
dramforever, I try to abstract away languages.
dramforever 2017-02-07 04:38:31
noan: I've seen worse influences :)
dibblego 2017-02-07 04:38:36
the first trap in scala is thinking there is sanity, even if just a little bit
noan 2017-02-07 04:38:42
dramforever, https://tpolecat.github.io/2013/11/13/list.html
noan 2017-02-07 04:39:04
Rob does the Lord's... or maybe Satan's work. I still don't know which.
dramforever 2017-02-07 04:39:38
It's good enough
merijn 2017-02-07 04:39:57
Sheo: GHC uses Cmm which is kinda based on C--, but not entirely the same (since C-- never really got wide adoption)
dramforever 2017-02-07 04:40:14
People say they don't understand monads because they can't see why it's useful :facepalm:
merijn 2017-02-07 04:40:21
Sheo: Additionally there's a new backend which uses LLVM instead of Cmm (I think...not 100% sure)
noan 2017-02-07 04:40:35
dramforever, nah. If I was trying to do this stuff I'm trying to learn in haskell right now I'd be staring at a compiler error where I lack an implicit instance of a CanBuildFrom[Satan'sAsshole] and I'd just start crying.
Sheo 2017-02-07 04:40:59
Oh, I thought that was just another name for c--. ty
tdammers 2017-02-07 04:41:01
usually, when people say "I don't understand monads", what they really mean is "I don't accept monads", except that they don't know it yet
dramforever 2017-02-07 04:41:13
They could be too confused
merijn 2017-02-07 04:41:37
Sheo: It started out as C-- proper, but it has evolved into a slightly different GHC specific dialect since there's no real incentive to stay C-- compatible
noan 2017-02-07 04:41:46
dibblego, define a functor for me, I forgot since you did it two years ago
noan 2017-02-07 04:41:48
<3
noan 2017-02-07 04:41:51
thanks dramforever
Sheo 2017-02-07 04:41:56
Oh ok, thanks.
tdammers 2017-02-07 04:42:04
what I mean is that there isn't a lot to understand there - >>= and return aren't exactly rocket science; it just takes a mental leap of faith to accept them as useful abstractions
dibblego 2017-02-07 04:42:10
noan: haskell or scala?
dramforever 2017-02-07 04:42:25
I've seen one so confused he/she asks How do monads handle these: 1. running multiple actions concurrently 2. running multiple actions concurrently, and only collect the results of those that terminate within a timeouut
noan 2017-02-07 04:42:26
either. Wait a minute
dramforever 2017-02-07 04:42:27
*timeout
noan 2017-02-07 04:42:34
https://en.wikipedia.org/wiki/Functor Is this just a morphism?
dramforever 2017-02-07 04:42:39
and WTF
jophish 2017-02-07 04:43:02
dramforever: sounds like a job for Applicative Functors!
dramforever 2017-02-07 04:43:07
Kinda like how do you control multiple motors with a pizza
dibblego 2017-02-07 04:43:15
class Functor f where fmap :: (a -> b) -> f a -> f b trait Functor[F[_]] { def fmap[A, B](f: A => B): F[A] => F[B] }
jophish 2017-02-07 04:43:21
burrito*
sshine 2017-02-07 04:43:31
applicative burritos?
sea_wulf 2017-02-07 04:43:39
Correct me if I'm wrong, but isn't a morphism a type of functor?
noan 2017-02-07 04:43:42
oh okay.
dramforever 2017-02-07 04:43:48
they perhaps confused the Italian food with the Italian Arduino or whatever
sshine 2017-02-07 04:44:00
sea_wulf, in what sense?
dramforever 2017-02-07 04:44:03
I think the level of confusion is about that bad
dramforever 2017-02-07 04:44:32
noan: You're welcome :)
noan 2017-02-07 04:44:41
dibblego, thingy that turns a function between two types into a function between two functors of those types
noan 2017-02-07 04:44:42
basically?
dramforever 2017-02-07 04:44:59
Getting Haskell concepts straight makes me happier :)