AkronCodeClub / edX-FP101x-Oct-2014

Study group for edX course FP101x beginning October 2014
8 stars 1 forks source link

Types and Classes Homework #14 #14

Closed rpottsoh closed 9 years ago

rpottsoh commented 9 years ago

This exercise seems pretty straight forward: what is the type of ["False", "True"]. If I read that I think it might be [String, String]. However, if I ask GHCi to evaluate the type it reports [[Char]]. None of the available answers is [[Char]]. To further confuse things, if I consider the list [False, True] I would consider this list's type to be [Bool] and indeed it is according to GHCi? So I am confused as to what the correct answer is as what GHCi reports is the type for the original list is not one of the available answers.... Any thoughts on this? Thanks.

PhilRunninger commented 9 years ago

Ryan,

You are correct to think it is [String], but remember that a String is just an array of Char, so [[Char]] is correct. Don't ask me why the output from ghci is different from the correct answer in the homework.

Phil


From: Ryan Pottsmailto:notifications@github.com Sent: ý10/ý27/ý2014 8:35 PM To: AkronCodeClub/edX-FP101x-Oct-2014mailto:edX-FP101x-Oct-2014@noreply.github.com Subject: [edX-FP101x-Oct-2014] Types and Classes Homework #14 (#14)

This exercise seems pretty straight forward: what is the type of ["False", "True"]. If I read that I think it might be [String, String]. However, if I ask GHCi to evaluate the type it reports [[Char]]. None of the available answers is [[Char]]. To further confuse things, if I consider the list [False, True] I would consider this list's type to be [Bool] and indeed it is according to GHCi? So I am confused as to what the correct answer is as what GHCi reports is the type for the original list is not one of the available answers.... Any thoughts on this? Thanks.

— Reply to this email directly or view it on GitHubhttps://github.com/AkronCodeClub/edX-FP101x-Oct-2014/issues/14.

rpottsoh commented 9 years ago

@PhilRunninger I remember from the lecture that String was briefly mentioned as being a sub-type (of Char) but it was never really explained in much detail. It is sure confusing when you think you thought out the answer and then when you test it you get something "like" it but exactly what was expected. I "saw the light" after I ended up picking the wrong answer, but it did help on the exercises that followed this one. I ended up doing a lot better on the second homework.

Thanks, Ryan

rickbacci commented 9 years ago

https://www.haskell.org/onlinereport/haskell2010/haskellch6.html#x13-1160006

A string is a list of characters. Its the same as and Int is a type of Num. I got it wrong too, i put [String, String]