miciek / grokkingfp-examples

All examples and exercises from the Grokking Functional Programming book
https://www.manning.com/books/grokking-functional-programming?utm_source=michal&utm_medium=affiliate&utm_campaign=book_khan_grokking_6_26_19&a_aid=michal&a_bid=7c041142
125 stars 49 forks source link

Cannot load src/main/scala/ch08_SchedulingMeetings.scala #154

Open gitgithan opened 1 year ago

gitgithan commented 1 year ago

I didn't exhaustively test, but at least :load src/main/scala/ch06_TvShows.scala loaded properly.

Looks like issues with using java implementations.

On a related note, in ch06_TvShows.scala there are multiple implementations of the same function (eg. extractName has Option, Either, Option, Either 4 appearances). How do I know which version got loaded? I read online that it's the last one that gets loaded, so i expect def extractName(rawShow: String): Either[String, String] from line 409 , but i got the Option version instead?

scala> ch06_TvShows.extractName
val res92: String => Option[String] = Lambda$7587/0x0000000802189fd8@707b5dea

Output for error loading chapter 8

scala> :load src/main/scala/ch08_SchedulingMeetings.scala
-- [E007] Type Mismatch Error: -------------------------------------------------
23 |    ch08_SchedulingMeetingsAPI.calendarEntriesApiCall(name).asScala.toList
   |    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |    Found:    List[MeetingTime]
   |    Required: List[MeetingTime²]
   |
   |    where:    MeetingTime  is a class
   |              MeetingTime² is a class
   |----------------------------------------------------------------------------
   | Explanation (enabled by `-explain`)
   |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   |
   | Tree: jdk.CollectionConverters.ListHasAsScala[MeetingTime](
   |   ch08_SchedulingMeetingsAPI.calendarEntriesApiCall(name)
   | ).asScala.toList
   | I tried to show that
   |   List[MeetingTime]
   | conforms to
   |   List[MeetingTime]
   | but the comparison trace ended with `false`:
   |
   |   ==> List[MeetingTime]  <:  List[MeetingTime]
   |     ==> MeetingTime  <:  MeetingTime
   |     <== MeetingTime  <:  MeetingTime = false
   |   <== List[MeetingTime]  <:  List[MeetingTime] = false
   |
   | The tests were made under the empty constraint
    ----------------------------------------------------------------------------
-- [E007] Type Mismatch Error: -------------------------------------------------
28 |    ch08_SchedulingMeetingsAPI.createMeetingApiCall(names.asJava, meetingTime)
   |                                                                  ^^^^^^^^^^^
   |                                   Found:    (meetingTime : MeetingTime)
   |                                   Required: MeetingTime²
   |
   |                                   where:    MeetingTime  is a class
   |                                             MeetingTime² is a class
   |----------------------------------------------------------------------------
   | Explanation (enabled by `-explain`)
   |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   |
   | Tree: meetingTime
   | I tried to show that
   |   (meetingTime : MeetingTime)
   | conforms to
   |   MeetingTime
   | but the comparison trace ended with `false`:
   |
   |   ==> (meetingTime : MeetingTime)  <:  MeetingTime
   |     ==> MeetingTime  <:  MeetingTime (left is approximated)
   |     <== MeetingTime  <:  MeetingTime (left is approximated) = false
   |   <== (meetingTime : MeetingTime)  <:  MeetingTime = false
   |
   | The tests were made under the empty constraint
    ----------------------------------------------------------------------------
2 errors found

Suggested improvements

I suggest changing scalacOptions ++= List("-unchecked"), to scalacOptions ++= List("-unchecked", "-deprecation", "-explain"), because both extra options have helped me understand outputs and enriches the learning experience, especially -explain. Maybe there are other helpful options i'm unaware of too.

GodefroyClair commented 7 months ago

I tried many loading many files from chapter 1 to 8 and everything worked except ch08_SchedulingMeetings.scala. @gitgithan: did you find a solution to load the file?