# need help understanding how to specify constraints on monads

13 messages
Open this post in threaded view
|

## need help understanding how to specify constraints on monads

Open this post in threaded view
|

## Re: need help understanding how to specify constraints on monads

Open this post in threaded view
|

## Re: need help understanding how to specify constraints on monads

Open this post in threaded view
|

## Re: need help understanding how to specify constraints on monads

Open this post in threaded view
|

## Re: need help understanding how to specify constraints on monads

Open this post in threaded view
|

## Re: need help understanding how to specify constraints on monads

Open this post in threaded view
|

## Re: need help understanding how to specify constraints on monads

Open this post in threaded view
|

## Re: need help understanding how to specify constraints on monads

Open this post in threaded view
|

## Re: need help understanding how to specify constraints on monads

Open this post in threaded view
|

## Re: need help understanding how to specify constraints on monads

 ​Thanks, Paolino. I will study this.I'll explain my larger goal. Probably should have started with that.I'm writing algorithms to optimize data structures by backtracking search.More specifically, I'm optimizing musical compositions. But I have several possible representations of a composition and I'd like to swap them in and out.I also have several ideas for a search algorithm. The search will function kind of like a chess program, adding notes to the composition one at a time and looking ahead N notes, then using some kind of fitness evaluation function to find the best "next move."There are variations on this algorithm possible. The fitness function will be computed by summing the fitness from "evaluation units" which, individually, look at only one aspect of good music. Together they have a more comprehensive view. I can easily try variations on the search by adding or removing "evaluation units".For another source of variation, I may use a fully deterministic algorithm, or I may use some pseudorandomness in choosing what paths to search, in various combinations.So how do I write a search algorithm when I don't know the type of the data structure or the evaluation units?My idea was to create a typeclass, Comp, parameterized on the the composition data structure ('comp'), the data type of a single "move" or step to be added, ('step'), and the type of an evaluation units ('eu').class Comp comp eu step | comp -> eu, comp -> step where  listPossibleSteps :: comp -> [step]  addStep :: comp -> step -> comp  evalComp :: eu -> comp -> compThis should offer all the necessary computations to implement backtracking search of many flavors.There's a lot more to how I want to implement this algorithm, mainly that I want to log "analytics" to be able to examine its behavior, so that's where the ReportLog data type and State (or possibly Writer) monad came into it, but never mind that for now. I'm probably not even on the right track with this much.D _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafeOnly members subscribed via the mailman list are allowed to post.
Open this post in threaded view
|

## Re: need help understanding how to specify constraints on monads

 On Thu, Jun 28, 2018 at 03:23:18PM -0700, Dennis Raddle wrote: > My idea was to create a typeclass, Comp, parameterized on the the > composition data structure ('comp'), the data type of a single "move" or > step to be added, ('step'), and the type of an evaluation units ('eu'). > > class Comp comp eu step | comp -> eu, comp -> step where >   listPossibleSteps :: comp -> [step] >   addStep :: comp -> step -> comp >   evalComp :: eu -> comp -> comp Have you considered just making a record?     data Comp comp eu step = Comp {       listPossibleSteps :: comp -> [step],       addStep :: comp -> step -> comp,       evalComp :: eu -> comp -> comp     } If you make it a class then you end up in the bizarre situation where you can only have one collection of functionality for each type `comp`. Tom _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafeOnly members subscribed via the mailman list are allowed to post.