Wie jmg sagte, ist das kein gültiges Haskell, also ist es gut, dass GHC es nicht kompiliert! Wenn Sie mit Java vertraut sind, sollten Sie sich Haskells Typklassen wie Java-Interfaces vorstellen. Wenn das nicht hilft, dann sollten Sie vielleicht lesen LYAHs Kapitel über Klassen .
Für Ihr Problem scheint es, dass Sie einen listenähnlichen Datentyp wünschen, der niemals null sein kann. Sie müssen nicht Test für eine solche Eigenschaft, können Sie sie statisch sicherstellen, indem Sie einen Datentyp Typs, der niemals leer sein kann:
-- Notice this data type can never have zero 'a' values!
data NonEmptyList a = NEL a (NonEmptyList a) | Singleton a
-- We can define basic operators for this, just like list has
-- You can't pattern match with them, but there are work-arounds for that if you want to ask
(.:) = NEL -- concatenate non-empty lists
nelHead :: NonEmptyList a -> a
nelHead (NEL a _) = a
nelHead (Singleton a) = a
nelTail :: NonEmptyList a -> Maybe (NonEmptyList a)
nelTail (NEL _ b) = Just b
nelTail _ = Nothing
nelTake :: Int -> NonEmptyList a -> NonEmptyList a
nelTake 1 (NEL a _) = Singleton a
nelTake 1 (Singleton a) = Singleton a
nelTake n (NEL a rest) = a .: nelTake (n-1) rest
nelDrop :: Int -> NonEmptyList a -> NonEmptyList a
nelDrop _ (Singleton _) = error "Perhaps I should have used the 'maybe' type"
nelDrop 1 (NEL a r) = r
nelDrop n (NEL a r) = nelDrop (n-1) r
Und so weiter und so fort. Es ist erwähnenswert nelTake
y nelDrop
sind teilweise, aber nelHead
ist total, lustig, da dies das Gegenteil von normalen Listen ist.