Skip to content

Instantly share code, notes, and snippets.

@jhusain
Last active December 20, 2017 06:08
Show Gist options
  • Save jhusain/17433cd7e66679383ed1d9a4a219f2e0 to your computer and use it in GitHub Desktop.
Save jhusain/17433cd7e66679383ed1d9a4a219f2e0 to your computer and use it in GitHub Desktop.
Functor instance won't compile
module Main where
import Prelude
import Control.Monad.Eff (Eff)
import Data.Foldable (fold)
import TryPureScript (DOM, h1, h2, p, text, list, indent, link, render, code)
import Data.Map (Map, lookup, insert, empty)
import Data.List
import Data.Either
import Data.Maybe
data Tuple a b = Tuple a b
data Primitive = String String | Boolean Boolean | Number Number | Null
data JsonValue = Object (Map String JsonValue) | Array (List JsonValue) | Primitive
data Key = Str String | Range Int Int
data KeySet = SingleKey Key | MultiKey Key
type Path = List String
type PathSet = List KeySet
data JsonGraphValue = JsonGraphObject (Map String JsonGraphValue) | Atom JsonValue | Ref Path | Error JsonValue | JsonPrimitive Primitive
newtype JsonGraphRecResult a = JsonGraphRecResult (Either String (Tuple (Maybe a) (List Path)))
instance jsonGraphRecResultFunctor :: Functor JsonGraphRecResult where
map f (JsonGraphRecResult (Right (Tuple (Just value) paths))) = JsonGraphRecResult (Right (Tuple (Just (f value)) paths))
map f value = value
newtype Blah a = Blah (Maybe a)
instance blahFunctor :: Functor Blah where
map f (Blah (Just x)) = Blah (Just (f x))
map f value = value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment