Skip to content

Instantly share code, notes, and snippets.

@dustingetz
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustingetz/62b7074208c7f1c203ac to your computer and use it in GitHub Desktop.
Save dustingetz/62b7074208c7f1c203ac to your computer and use it in GitHub Desktop.
@dustingetz
Copy link
Author

instance Expr Program where
  lit (IVal n) = [PushI n]
  lit (BVal n) = [PushB n]
  add (IVal l) (IVal r) = [PushI l, PushI r, StackVM.Add]
  add (BVal l) (BVal r) = [PushB l, PushB r, StackVM.Add]
  mul (IVal l) (IVal r) = [PushI l, PushI r, StackVM.Mul]
  mul (BVal l) (BVal r) = [PushB l, PushB r, StackVM.Mul]
cpu.hs:11:10:
    Illegal instance declaration for ‘Expr Program’
      (All instance types must be of the form (T a1 ... an)
       where a1 ... an are *distinct type variables*,
       and each type variable appears at most once in the instance head.
       Use FlexibleInstances if you want to disable this.)
    In the instance declaration for ‘Expr Program’
Failed, modules loaded: Parser, ExprT, StackVM, Calc.

@dustingetz
Copy link
Author

Here is a second attempt

instance Expr Program where
  lit (IVal n) = [PushI n]
  lit (BVal n) = [PushB n]
  add l r = l ++ r ++ [StackVM.Add]
  mul l r = l ++ r ++ [StackVM.Mul]
Illegal instance declaration for ‘Expr Program’
      (All instance types must be of the form (T a1 ... an)
       where a1 ... an are *distinct type variables*,
       and each type variable appears at most once in the instance head.
       Use FlexibleInstances if you want to disable this.)
    In the instance declaration for ‘Expr Program’
Failed, modules loaded: Parser, ExprT, StackVM, Calc.

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