how to translate Haskell into Scalaz?
Posted
by
TOB
on Stack Overflow
See other posts from Stack Overflow
or by TOB
Published on 2012-03-30T10:25:02Z
Indexed on
2012/03/30
11:29 UTC
Read the original article
Hit count: 265
One of my high school students and I are going to try to do a port of Haskell's Parsec parser combinator library into Scala. (It has the advantage over Scala's built-in parsing library that you can pass state around fairly easily because all the parsers are monads.)
The first hitch I've come across is trying to figure out how Functor works in scalaz. Can someone explain how to convert this Haskell code:
data Reply s u a = Ok a !(State s u) ParseError
| Error ParseError
instance Functor (Reply s u) where
fmap f (Ok x s e) = Ok (f x) s e
fmap _ (Error e) = Error e -- XXX
into Scala (using Scalaz, I assume). I got as far as
sealed abstract class Reply[S, U, A]
case class Ok[S, U, A](a: A, state: State[S, U], error: ParseError)
extends Reply[S, U, A]
case class Error[S, U, A](error: ParseError) extends Reply[S, U, A]
and know that I should make Reply
extend the scalaz.Functor
trait, but I can't figure out how to do that. (Mostly I'm having trouble figuring out what the F[_]
parameter does.)
Any help appreciated!
Thanks, Todd
© Stack Overflow or respective owner