Andy Melnikov (nponeccop) wrote,
Andy Melnikov

Вторая версия

{-# LANGUAGE NoMonomorphismRestriction, DeriveFunctor #-}

import Data.Functor.Foldable

data NodeBase a b = NodeBase 
	{ item :: a
	, next :: b 
	} deriving (Functor, Show)
newtype ListBase a b = ListBase (Maybe (NodeBase a b)) deriving (Functor, Show)

type ListPtr a = Fix (ListBase a)
type ListNode a = ListBase a (ListPtr a)

nil = Fix . ListBase $ Nothing
cons a b = Fix . ListBase . Just $ NodeBase a b

  • Post a new comment


    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.