Skip to content

Instantly share code, notes, and snippets.

@bblum
Created October 13, 2012 15:36
Show Gist options
  • Select an option

  • Save bblum/3885033 to your computer and use it in GitHub Desktop.

Select an option

Save bblum/3885033 to your computer and use it in GitHub Desktop.
An attempt at translating https://gist.github.com/3885017 to haskell that doesn't compile.
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}
module Main where
import Control.Monad (when)
import Control.Applicative ((<$>))
class Nat n
newtype Zero = Zero ()
newtype Suc n = Suc n
instance Nat Zero
instance (Nat n) => Nat (Suc n)
class (Nat n) => List t n v where
each :: (Monad m, List t n v) => (t -> m Bool) -> v -> m ()
newtype Nil n = Nil ()
newtype (Nat n, List t n v) => Cons t n v = Cons (t, v)
instance List t Zero (Nil Zero) where
each f v = return ()
instance (Nat n, List t n v) => List t (Suc n) (Cons t n v) where
each f (Cons(t,v)) = do b <- f t; when b $ each f v
-- This also doesn't compile, even if you change the above into return ().
-- main = each (\x -> do putStrLn $ show x; return True) Cons(1,Cons(2,Cons(3,Nil()))))
main = return ()
@bblum
Copy link
Author

bblum commented Oct 13, 2012

List.hs:26:48:
Ambiguous type variable n0' in the constraint: (List t n0 v) arising from a use ofeach'
Probable fix: add a type signature that fixes these type variable(s)
In the second argument of ($)', namelyeach f v'
In the expression: when b $ each f v
In the expression:
do { b <- f t;
when b $ each f v }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment