Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 03:49
    som-snytt synchronize #8885
  • 00:28
    som-snytt commented #8885
  • 00:24
    som-snytt synchronize #8885
  • Feb 28 23:52
    som-snytt review_requested #9519
  • Feb 28 23:52
    som-snytt labeled #9519
  • Feb 28 23:05
    som-snytt commented #12355
  • Feb 28 20:23
    arixmkii opened #12355
  • Feb 28 17:06
    SethTisue transferred #9727
  • Feb 28 17:01
    som-snytt commented #9727
  • Feb 28 16:36
    som-snytt commented #9727
  • Feb 28 15:57
    jxnu-liguobin commented #9518
  • Feb 28 12:11
    xhudik opened #1941
  • Feb 28 02:33

    SethTisue on 2.12.x

    2.12: new Scala SHA (compare)

  • Feb 28 01:22
    SethTisue labeled #1939
  • Feb 28 01:21
    SethTisue commented #1939
  • Feb 27 21:16
    xhudik opened #1940
  • Feb 27 19:23
    som-snytt synchronize #9526
  • Feb 27 18:35
    qamar2 edited #1939
  • Feb 27 18:34
    qamar2 opened #1939
  • Feb 27 07:02
    som-snytt commented #12354
Soren
@srnb_gitlab
Don't let me be a linguist or I will remove the distinction between phonemes and morphemes >:]
Ichoran
@Ichoran
That would be really brutal for everyone who knows current English.
("900 of the 1000 most common words don't look the same anymore.")
Soren
@srnb_gitlab
Not in English probably
I hate having thoughts that can't be expressed in English and English is the only language I know more than a few words in :sob:
Ichoran
@Ichoran
I mean, unless you just discard one of the two ideas, but don't actually change any languages. You could do that, I suppose :joy:
("Pay no attention to the distinction between speech and written language!")
Soren
@srnb_gitlab
I'm a terrible linguist haha
If only there was enough time on the planet to 100% Computer Science so I could move on to Linguistics :(
Ichoran
@Ichoran
Linguistics seems like a biased random walk through the space of things people can produce with their vocal cords and detect with their ears and teach to each other, to which we give ad-hoc explanations after the fact.
Kind of like Perl, I suppose.
Soren
@srnb_gitlab
Perl is a language that was built to do linguistic things, right?
Text manipulation
So, a few degrees of separation
Ichoran
@Ichoran
If that counts.
Soren
@srnb_gitlab
Now AppleScript,
AppleScript is kinda cool because it usually reads like good English
Ichoran
@Ichoran
Anyway, I'd better get back to working on things I actually know about.
Soren
@srnb_gitlab
I'd better get back to learning things I don't know about so I can graduate high school :sob:
ritschwumm
@ritschwumm
@srnb_gitlab afaik applescript spoke japanese, too - with a slightly un-japanese grammar, though.
David
@chugua99_twitter

Could you help me to create this algorithm?

Implement in Scala an algorithm which allows to find the first occurrence of a character in a string. If the character is found, return its position in the sequence, otherwise return -1. String = ”Scala”, Character = ' c'→ 1

Martijn Hoekstra
@martijnhoekstra
what have you tried so far, where are you getting stuck?
David
@chugua99_twitter
I have no idea how to start, I am beginner in this language
Martijn Hoekstra
@martijnhoekstra
here is a start for basics in the language: https://docs.scala-lang.org/tour/basics.html
Renan Reis
@renanreismartins

Hello, I'm going through the Functional Programming in Scala and on the chapter about State we have:
case class State[S, +A](run: S => (A, S))

then we have a method
def simulateMachine(inputs: List[Input]): State[Machine, (Int, Int)]

later on:

val m: Machine = Machine(true, 5, 10)
Candy.simulateMachine(inputs).run(m)

What is making me confused is that "m" is of type machine and "run" expects a "S => (A, S)" function... so how could I pass Machine to "run"?

Gavin Bisesi
@Daenyth
In this case simulateMachine's S is Machine
State[Machine, *] so run takes S which is Machine
run provides the "initial" state, and then things go from there
1 reply
Luis Miguel Mejía Suárez
@BalmungSan
@renanreismartins run does not expects a function, run IS A function, you are calling it with the initial state.
(btw, please do not use threads, they are hard to read)
Renan Reis
@renanreismartins
Sorry, I did not know about the thread etiquete.
Rob Norris
@tpolecat
There is no way you would have known.
Renan Reis
@renanreismartins
@BalmungSan when you say run is a function, where is it defined?
Fabio Labella
@SystemFw
State has a field run of type S => (A, S) (a function from S to a tuple of A and S)
when you say .run, you access that field
when you add (), you call Function.apply (under the hood) therefore passing the S to the function
the S type parameter in this case is equal to Machine, which is why you can pass a Machine to the function
Renan Reis
@renanreismartins
@SystemFw thanks for the explanation. Kinda makes sense to me, but where is the definition of run where it takes the S and makes it on a (A, S) ?
Luis Miguel Mejía Suárez
@BalmungSan
@renanreismartins yeah no worries about the thread, sorry if I sounded rude.
Fabio already explained it pretty well but maybe this helps, the code is expanded like this:
Candy.simulateMachine(inputs).run.apply(m) // we are calling the apply method on the run value which is an instance of the function class
Martijn Hoekstra
@martijnhoekstra
if you have a val x: Int => Int it's a value that returns a function
Luis Miguel Mejía Suárez
@BalmungSan
Here: final case class State[S, +A](run: S => (A, S)) when you create an State you have to pass a Function.
Basically the State data type is just a convenient wrapper over a S => (A, S) Function.
Fabio Labella
@SystemFw
@renanreismartins actually, that's the key conceptual point about State

when you create an State you have to pass a Function.

I think this view is confusing

but where is the definition of run where it takes the S and

so you have various State computations, right?

which you can combine together with map and flatMap and pure etc
Renan Reis
@renanreismartins
yes
Fabio Labella
@SystemFw
so, those computations are building the function
so what's the starting point?
the initial mini functions that get combined together