Search Results

Search found 5 results on 1 pages for 'monoids'.

Page 1/1 | 1 

  • Examples of monoids/semigroups in programming

    - by jkff
    It is well-known that monoids are stunningly ubiquitous in programing. They are so ubiquitous and so useful that I, as a 'hobby project', am working on a system that is completely based on their properties (distributed data aggregation). To make the system useful I need useful monoids :) I already know of these: Numeric or matrix sum Numeric or matrix product Minimum or maximum under a total order with a top or bottom element (more generally, join or meet in a bounded lattice, or even more generally, product or coproduct in a category) Set union Map union where conflicting values are joined using a monoid Intersection of subsets of a finite set (or just set intersection if we speak about semigroups) Intersection of maps with a bounded key domain (same here) Merge of sorted sequences, perhaps with joining key-equal values in a different monoid/semigroup Bounded merge of sorted lists (same as above, but we take the top N of the result) Cartesian product of two monoids or semigroups List concatenation Endomorphism composition. Now, let us define a quasi-property of an operation as a property that holds up to an equivalence relation. For example, list concatenation is quasi-commutative if we consider lists of equal length or with identical contents up to permutation to be equivalent. Here are some quasi-monoids and quasi-commutative monoids and semigroups: Any (a+b = a or b, if we consider all elements of the carrier set to be equivalent) Any satisfying predicate (a+b = the one of a and b that is non-null and satisfies some predicate P, if none does then null; if we consider all elements satisfying P equivalent) Bounded mixture of random samples (xs+ys = a random sample of size N from the concatenation of xs and ys; if we consider any two samples with the same distribution as the whole dataset to be equivalent) Bounded mixture of weighted random samples Which others do exist?

    Read the article

  • Resources for learning Monads, Functors, Monoids, Arrows etc

    - by Dony Borris
    Can you people please suggest some good books / weblinks from where I can get to learn about above mentioned concepts? (Please note that I am a Java programmer and have NO prior experience with functional programming. I have been studying Scala since last one month and would appreciate the resources that try to teach the above mentioned concepts with Scala. (or even Java, if posible))

    Read the article

  • Are monads Writer m and Either e categorically dual?

    - by sdcvvc
    I noticed there is a dual relation between Writer m and Either e monads. If m is a monoid, then unit :: () -> m join :: (m,m) -> m can be used to form a monad: return is composition: a -> ((),a) -> (m,a) join is composition: (m,(m,a)) -> ((m,m),a) -> (m,a) The dual of () is Void (empty type), the dual of product is coproduct. Every type e can be given "comonoid" structure: unit :: Void -> e join :: Either e e -> e in the obvious way. Now, return is composition: a -> Either Void a -> Either e a join is composition: Either e (Either e a) -> Either (Either e e) a -> Either e a and this is the Either e monad. The arrows follow exactly the same pattern. Question: Is it possible to write a single generic code that will be able to perform both as Either e and as Writer m depending on the monoid given?

    Read the article

  • Choosing the non-empty Monoid

    - by Nikita Volkov
    I need a function which will choose a non-empty monoid. For a list this will mean the following behaviour: > [1] `mor` [] [1] > [1] `mor` [2] [1] > [] `mor` [2] [2] Now, I've actually implemented it but am wondering wether there exists some standard alternative, because it seems to be a kind of a common case. Unfortunately Hoogle doesn't help. Here's my implementation: mor :: (Eq a, Monoid a) => a -> a -> a mor a b = if a /= mempty then a else b

    Read the article

  • What exactly is a Monad?

    - by WeNeedAnswers
    Can someone please explain to me what a Monad is. I think I grasp Monoids and I grasp that they basically control the input of state into a system. I just look at the text in Haskell and glaze over. A simple example in python would be great. My current understanding is that a Monoid is a procedural piece of code that needs to be read from top to bottom in sequence with the output being the input for the function. I think that I may even got that wrong, but hey I am here to learn.

    Read the article

1