Skip to content

Instantly share code, notes, and snippets.

@lanwin
Last active December 25, 2015 11:49
Show Gist options
  • Save lanwin/6971441 to your computer and use it in GitHub Desktop.
Save lanwin/6971441 to your computer and use it in GitHub Desktop.
Less types and more functions.
As lisp programmers have know for a long time it is better to have a smallish number of ubiquitous data types and a large number of small functions that work on them, than to have a large number of data types and a small number of functions that work on them.
@lanwin
Copy link
Author

lanwin commented Oct 14, 2013

I dont think I am sure what that means. From what I guess is that its better to have a file und represented as string and have functions like the dotnet file api instead of a type like FileInfo. (Yes i know FileInfo id very OOish)

@forki
Copy link

forki commented Oct 14, 2013

It doesn't say you should use string. It's better to have a separate file data type that can be distinguished from string. But yes we want to separate the data from the functions.

@BjRo
Copy link

BjRo commented Oct 14, 2013

Well functional programming in general follows the principle of building larger things from small basic, reusable units.

If you take a look at the datatypes used in FP, they don't follow a hierarchical model (like inheritance) but are rather composed out of the core basic datatypes (List/Array/Tuple/Hash). The heart of every FP language is a core group of function definitions that can work on those data types .... and there are a lot of them :-)

Even the Record abstraction in Elixir for example is in the end just a Tuple and can be used with every function that can handle a tuple.

@forki
Copy link

forki commented Oct 14, 2013

It's better to have a separate file data type that can be distinguished from string.

But of course all string functions should also work on the "Content" property of the file. But a file is usally more than just a string. You have a FileName and maybe other functions which allow to process the file sequentially. You don't want to load the big files completely into the RAM.

@forki
Copy link

forki commented Oct 14, 2013

But in order to understand the statement keep in mind Lisp has no strong typing.

All Lisp functions should work on the generic data types like array, map,...

If you look at ML, F# or haskell then you'll see that you can have both. You can define generic functions which work on complicated data structures and keep the types distinguishable.

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