Learning Haskell Week02 - Intro To Types

Пікірлер: 12

  • @giovannimuller4555
    @giovannimuller45558 ай бұрын

    great video, what presentation tool do you use? is ist powerpoint? if yes, how is the layout called?

  • @hurstilthymy4943
    @hurstilthymy49433 жыл бұрын

    Do you have answers to the exercises?

  • @user-ls5zh4xy5g
    @user-ls5zh4xy5g3 жыл бұрын

    No idea how to do firstHalf but lastHalf :: [a] -> [a] lastHalf xs = let halfway xs = length xs `div` 2 listCat xs 0 = xs listCat (x:xs) ind = listCat xs (ind - 1) in listCat xs (halfway xs) which works but it's terrible and I hate it. Obviously this is not the way you wanted us to do this exercise, it says to use firstHalf to define lastHalf. I'm probably missing something obvious here but right now I'm honestly stumped

  • @saivedamasetty6677
    @saivedamasetty66772 жыл бұрын

    Are you referring to haskelly extension for type signature? Or any other extension? I installed haskelly but it does not work.

  • @CurtisDAlves

    @CurtisDAlves

    2 жыл бұрын

    The haskell extension will give you the haskell-language-server which gives you the type signature

  • @Bijay007
    @Bijay0073 жыл бұрын

    initC :: [a] -> [a] initC [n,m] = [n] Here, :type a is defined as a String. But you showed in the video in order to write function with string type( I don't know if I am saying this right), it must be something like a = ['t','u'] or a= "tu".

  • @CurtisDAlves

    @CurtisDAlves

    3 жыл бұрын

    So the values ['t','u'] and "tu" both have the type String (they are actually the same value just written with different syntax). What I was emphasizing here is that a String type is actually just a [Char] type. initC :: [a] ->[a] means that it works on a list of any type a, including Char but not exclusive to Char. This means initC will work on Strings, or a [Int], or [Bool], or a list of anything

  • @Bijay007

    @Bijay007

    3 жыл бұрын

    @@CurtisDAlves I understand that initC will work on any type and the respective type signature will be displayed above. What I don't understand is in this case, how is a String being represented as [n,m] and not ['n','m'] or "nm".

  • @CurtisDAlves

    @CurtisDAlves

    3 жыл бұрын

    @@Bijay007 [n,m] would be a string if the variables n and m are of type Char. (I should also mention your definition of initC [n,m] = [n] is wrong in that it only works on lists with two elements)

  • @Bijay007

    @Bijay007

    3 жыл бұрын

    @@CurtisDAlves OK so 2 questions, 1) Doesn't on the right hand side of the equation need to be in single quotation marks ' ' if it hasn't been defined yet to be considered as a Char? 2)InitC[b,n,m]=[b,n]. Is this correct?

  • @CurtisDAlves

    @CurtisDAlves

    3 жыл бұрын

    @@Bijay007 1) so you seem to be confused between the difference of a variable and a value. Consider this function: createString x = ['a',x], if i were to call the function createString 'b' it would make the list ['a','b'] which is the same as "ab". In this case, 'a' is a value, and x is a variable (a placeholder for any Char). 2) nope you're still pattern matching and now your function only works on lists of with 3 elements