data type of ParsecT
data ParsecT s u m a
so here 's u m a' are any types, like generics in Scala/Java 🍱
trait Parsec[S,U,M,A]
(<|>) :: Monad m => ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
Here you are constraining m to the type Monad. It helps to read the types from right to left:
<|> goesParsecT takes type parameters s u m a,
Functions in Haskell are automatically curried, i.e if a funct
val addTwoNums: Int Int => Int = (x, y) => x + y
Enter Haskell REPL ghci
Prelude> let addTwoNums x y = x + y :: Integer -> Integer
Prelude> :t addTwoNums
addTwoNums :: Num a => a -> a -> a
Prelude> let incNum = addTwoNums 1
Prelude> :t incNum
incNum :: Integer -> Integer
Prelude> addTwoNums 3 3
6
Prelude> incNum 3
4
In Haskell, like in Scala, declaring the type is optional
addTwoNums :: Int -> Int //optionally declare the type when not inside an .hs file
addTwoNums x y = x + y
- the do sugar, mmmm 🍧
// a stream seems to be passed implicitly into this 'monad'
do
x <- many (noneOf "\"")
return x
desugars to ... -- many (noneOf "") >>= \x -> ...
>>
for chaining without passing along the internal value, will short circuit when one monad in the chain fails.
monadA >> monadB >> monadC // if one fails, then the chain stops and returns the `failed` monad representation.
>>=
for passing the internal value on one monad to the next monad in the chain, likeflatMap
in Scala.
monadA >>= \a -> (nextMonad a) >>= \b -> (nextMonad b) -> combineThemAll a b c
- The
$
is like()
and is used for passing arguments to a function it has the lowest precedence and is right associative.
Prelude> incNum $ 3
// a where ParsecT is a type with a constrain on 'a' that it must be a Char see: data ParsecT s u m a
letter :: Stream s m Char => ParsecT s u m Char
Haskell allows you to make these "anonymous types"
instance Functor (ParsecT s u m) where fmap f p = parsecMap f p are instances like scala implicit type classes? and like that! Found the perfect blog post "Typeclasses define behaviour for a particular type and typeclass instances implement that behaviour. In this sense, typeclasses are interfaces and typeclass instances are implementations of those interfaces. You do not instantiate the implementations, the compiler does, and it does so by matching the types"
- cabal is the the package manager for Haskel
- Hoogle
- System.io.unsafeIO!
- debug, trace.
- data types, instance (implicit TC scala?)
- monadic chaining:
do
x <- myMonad
return x
syntatic sugar...desugars to >>=
like Scala
>>=
when you need to pass along the value
>>
when you don't need to pass along a value
- Haskell (Glasgow '90s) hence ghc [Glasgow Haskell compiler] vs ML (University of Edinburgh 1973 Robert Milner )