Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    toxicafunk
    @toxicafunk
    hi
    zhangjunjun
    @zhjunjun

    sealed trait List[+A] // List data type, parameterized on a type, A

    case object Nil extends List[Nothing] // A List data constructor representing the empty list

    why there use object Nil ? why not class?

    sealed trait List[+A]
    case object Nil extends List[Nothing]
    toxicafunk
    @toxicafunk
    You only need 1 instance of the empty case (Nil)
    Objects in scala are singletons
    So you make Nil a singleton since you don't need different instances for List[Nothing], one is enough to cover all cases
    zhangjunjun
    @zhjunjun
    very nice, many thanks! @toxicafunk
    MachineLearning
    @zhangshengshan
    why there is not a Nil Object for Tree in Section 3 ?
    there may be a branch which has only left branch or only right. such like Branch(Leaf(1), NilObj)
    i am wondering is this Tree is a possible form of the ADT TREE ?
    Christopher Davenport
    @ChristopherDavenport
    That would just be Leaf(1) in the structure.
    MachineLearning
    @zhangshengshan
    Leaf(1) means there is a Leaf Node and the value contained in the Leaf is 1
    while I think the Leaf could also be a null
    and there is no value , cause there is not a container at all.
    Christopher Davenport
    @ChristopherDavenport
    A leafy tree is a nonempty structure by design.
    That being said, you can create a structure in the light that you want.
    I wrote that up at some point but I lost it into the void.
    MachineLearning
    @zhangshengshan
    is not a binary Tree ?
    Binary Tree could have a Null branch I think .
    while designed by C /C ++ it could be defined as
    Tree{ Tree left , Tree right }
    and both left and right could be null poiter I think
    Christopher Davenport
    @ChristopherDavenport
    This is generally not that sort of tree.
    MachineLearning
    @zhangshengshan
    OK thank you 啊
    if this tree is designed with no Null branch
    i can understand the code in the answer
    MachineLearning
    @zhangshengshan
    0
    MachineLearning
    @zhangshengshan
    image.png
    Christopher Davenport
    @ChristopherDavenport
    You need to define one of them.
    In one of the instances, then the other will work. If you use the default then it will spin forever.
    Generally speaking most of the time you leave one abstract to make that clear, and more advanced users can define in terms of a specific operation if they'd like.
    Make sense @zhjunjun ?
    MachineLearning
    @zhangshengshan
    @ChristopherDavenport you mean one of the two default methods should be implemented in a class or object that extends Traverse trait ? Oh , i understand . thank you very much .
    Christopher Davenport
    @ChristopherDavenport
    Precisely. :smile:
    zhangjunjun
    @zhjunjun
    hi
    Christopher Davenport
    @ChristopherDavenport
    :wave:
    padzikm
    @padzikm
    Hi, in exercise 6.10 (https://github.com/fpinscala/fpinscala/blob/master/answerkey/state/10.answer.scala) sequenceViaFoldLeft is described to be stack-safe, but it's built from stack of functions calling each other (results of eagerly going through list and executing map2) - so executing it will result in stack as deep as list length. On the other hand sequence implemented with private go function will not go through the list eagerly, but return one object State with one function which is tailrec. Am I correct or where am I wrong?
    Ghost
    @ghost~5d739909d73408ce4fca44d7
    Hi, in Listing 7.5 the outer Callable will block waiting for the "inner" task to compelete. What is "inner" task? and Why should Callable waits "inner" task?
    1.PNG
    Zachary LeFevre
    @zachlefevre

    a(es) submits a Callable to the ExecutorService when a is a forked Par. If you only have one thread available, and that thread is running the outer Callable submitted to the ExecutorService, then as soon as it calls .call() it is going to block waiting for a thread to be available. Therefore the only thread will be sitting and waiting for another thread. This is a deadlock.
    See Example 7.8

    @YoungSeoChoi

    SC
    @arbeiter
    I have a question from the fpinscala book:
    //Given a function like: 
    def unit[A](a: A): Par[A]
    def fork[A](a: => Par[A]): Par[A]
    def lazyUnit[A](a: => A): Par[A] = fork(unit(a))

    //Implement: 
    def asyncF[A,B](f: A => B): A => Par[B]
    my question is how is asyncF supposed to be called.
    I peeked at the solution and it isn't obvious to me what: A => Par[B] in the asyncF definition means
    a function that takes A and returns Par[B]?
    I think the f: A => B means f takes an arg A and returns a lazy response B.
    so does asyncF take this function f, and change it to a function that takes A and returns a lazy response Par[B]?
    toxicafunk
    @toxicafunk
    function f is a function that takes an A and returns Par[B]
    A => Par[B] is syntax sugar for Function1[-A, +Par[B]]
    matrixbot
    @matrixbot
    @toxicafunk:matrix.org testing riot.im integration
    Anirudh Vyas
    @AnirudhVyas