[Haskell-cafe] Representing record subtypes, sort of.

Imran Hameed idhameed at gmail.com
Thu Nov 13 08:40:49 UTC 2014


On Mon, Nov 10, 2014 at 5:44 PM, Kannan Goundan <kannan at cakoose.com> wrote:
> (I'm assuming some way of specifying that FsEntry will only ever have those
> two subtypes.)
>
> How would you represent this in Haskell?

data FsEntry a = FsEntry { id :: String, info :: a }

data FileInfo = FileInfo { modified :: Double, size :: Int }

data FolderInfo = FolderInfo { owner :: String }

data FsListEntry = File (FsEntry FileInfo) | Folder (FsEntry FolderInfo)

type Path = String

listFolder :: Path -> [FsListEntry]
createFile :: Path -> FsEntry FileInfo
createFolder :: Path -> FsEntry FolderInfo
functionThatExpectsAnyFsEntry :: FsEntry a -> ()


More information about the Haskell-Cafe mailing list