Skip to content

Haskell code to find substructures within lists along with their selectors.

Notifications You must be signed in to change notification settings

raw-ash/List-To-Tree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

List To Tree

A functional programming approach for converting a list into a binary tree. Haskell library doesn't seem to have such a function or I'm just bad at searching. Anyways, this peace of code have certain functions operating on list and trees.

Idea!

The idea for this code was obtained, while doing a project on program synthesis. We required a function which can tell us whether a list is a substructure of another or not and if it is, then get the appropriate set of selectors to obtain it.

Substructure

What does substructure means ? Well, we know that internally, and hopefully, lists in Haskell are represented using 'cons - nil' constructors in the form of a tree. Example: List [1,2,3] is represented as

  :
 / \
1   :
   / \
  2   :
     / \
    3   []

Here, ":" represents cons constructor and "[ ]" represents nil constructor of list data type. Now, Sub-structure of this lists are those lists which are part of this tree, and are tree by themselves, and those are: [1,2,3], [2,3], [3] and [ ], and associated selectors are id, tail.id, tail.tail.id and tail.tail.tail.id respectively.

About

Haskell code to find substructures within lists along with their selectors.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published