Answered step by step
Verified Expert Solution
Question
1 Approved Answer
package functional import functional.data. { Graph , Tree } trait Foldable [ F [ _ ] ] : def fold Monoid [ A ] def
package functional
import functional.data.Graph Tree
trait FoldableF:
def fold Monoid
def foldMap Monoid :
object ListFoldable extends FoldableList:
override def fold : List m: Monoid : match
case Nil mempty
case fold
override def foldMap List Monoid
object TreeFoldable TODO
object GraphFoldable TODO
def wordCountFt: FStringf: FoldableF: Int
def charCountFt: FStringf: FoldableF: Int
a Implement foldables points
The foldables for the data structures List, Tree and Graph need to be implemented.
Important: The given interfaces do not use any implicit parameters. You need to find the appropriate monoids explicitly
passed as a parameter.
Hints:
Two graphs can be merged using the monoid GraphMerge see task
The neighboring nodes of a graph can be edited using ListFoldable.
b Apply foldables points
Task: Implement the two methods wordCount and charCount in functional.Foldable. The method
Example: wordCountListhello world", "foo bar"ListFoldable
charCount should return the total number of characters in the strings contained within the foldable data structure.
Example: charCountListhello world", "foo bar"ListFoldable
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started