Skip to content

Instantly share code, notes, and snippets.

@kseo
Created February 11, 2016 11:23
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 kseo/d516e263fa8c5207d8f5 to your computer and use it in GitHub Desktop.
Save kseo/d516e263fa8c5207d8f5 to your computer and use it in GitHub Desktop.
Polymorphic recursion
import Prelude hiding (length)
data Nested a = a :<: (Nested [a]) | Epsilon
infixr 5 :<:
nested = 1 :<: [2,3,4] :<: [[4,5],[7],[8,9]] :<: Epsilon
length :: Nested a -> Int
length Epsilon = 0
length (_ :<: xs) = 1 + length xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment