Skip to main content

Home/ Haskell/ Group items tagged existential

Rss Feed Group items tagged

Javier Neira

Existential type - HaskellWiki - 0 views

  • First of all, it is now impossible for a function to demand a Worker having a specific type of buffer. Second, the type of foo can now be derived automatically without needing an explicit type signature. (No monomorphism restriction.) Thirdly, since code now has no idea what type the buffer function returns, you are more limited in what you can do to it.
  • This illustrates creating a heterogeneous list, all of whose members implement "Show", and progressing through that list to show these items: data Obj = forall a. (Show a) => Obj a   xs :: [Obj] xs = [Obj 1, Obj "foo", Obj 'c']   doShow :: [Obj] -> String doShow [] = "" doShow ((Obj x):xs) = show x ++ doShow xs With output: doShow xs ==> "1\"foo\"'c'"
  • Existential types in conjunction with type classes can be used to emulate the dynamic dispatch mechanism of object oriented programming languages. To illustrate this concept I show how a classic example from object oriented programming can be encoded in Haskell.
Javier Neira

Learning Haskell Notes - 0 views

  • 8. Functors
  • A "functor" is a structured collection (or container) type with a method (fmap) that accepts a method and applies that method to the members of the collection yielding an isomorphic collection of values of a (possibly) new type. Is this right?
  • Every monad is a functor, but not the other way around; a monad is a functor PLUS functions >>= and return satisfying some laws
  • ...4 more annotations...
  • a functor is a type constructor PLUS a function fmap satisfying some laws.
  • I think it's better to use existentials, as they let you define multiple instances for the same type.
  • People tend to forget that the major difference between ADT's and OO-style classes is really only that with a class you can have many instances in the same program simultaneously, whereas with an ADT you can have only one; but the ADT implementation is still interchangeable.
  • sequence :: Monad m => [m a] -> m [a]
1 - 2 of 2
Showing 20 items per page