Eating carbohydrates before bed has become a hot topic in nutrition, and some people think its a bad idea. This often comes from the belief that eating carbs before you go to sleep leads to weight gain. There is some evidence to support this argument, but all carbohydrates are not equal, and certain types of carbohydrates can help you lose weight and get a good night sleep.
Eating fibre has been shown to increase the levels of “good” bacteria, such as Bifidobacteria, in the digestive system. Bifidobacteria have been shown to produce all sorts of hormones - including serotonin a precursor to melatonin - and metabolites that improve gut health, lower body fat, lower stress (cortisol), and enhance cognative function. There is also evidence that fibre can help improve the quality of sleep.
A 2016 study took 26 adults (13 men and 13 women) aged between 30-45years and tested how different diets affected sleep. The diets included changes in fibre, saturated fat and sugar.  Researches found that having meals rich in fibre improved the quality of deep sleep and the speed at which volunteers got to sleep (down from 29minutes to 17minutes). The diets high in saturated fat and sugar were associated with arousals and led to poorer quality sleep.
One of the leading researchers, Dr. St-Onge pointed out, “The finding that diet can influence sleep has tremendous health implications, given the increasing recognition of the role sleep has in the development of chronic disorders such as hypertension (stress), diabetes and cardiovascular disease.” 
One amazing fibre that Bifidobacteria seem to thrive on is Resistance Starch (RS). RS, as the name suggests, resists digestion in the stomach and small intestine and reaches the colon largly intake. Instead of causing your blood sugar to spike, as you would expect from some carbohydrates, RS acts more like a fibre. We don’t digest the calories from RS, and we don’t see blood sugar spikes, or an insulin spike, which explains why it does not cause weight gain. RS can be useful for those following a high-fat diet (like the KetoDiet) as some preliminary studies are suggesting a low-carb diet can starve a lot of the good bacteria in the gut and therefore impact health and longevity. Interestingly, resistant starch is prebiotic.
Consider RS to be a “super-fertiliser” for your healthy gut bacteria or gut microbiome, which profoundly connects to almost every part of your health. Researchers link gut flora imbalances with obesity, diabetes, heart disease, autoimmune disease, inflammatory bowel disease (IBS), cancer, depression, anxiety, and autism.
Once RS reaches the large intestine, it's a valuable source of nutrients for the “good” bacteria that digests it and releases butyrate, which is a powerful anti-inflammatory that strengthens the gut wall and may decrease the risk of colon cancer. [2,3]
A diet rich in RS has been linked to reduced gut inflammation and reduced risk of type 2 diabetes and obesity. [4,5]
Resistant starch can also improve insulin sensitivity and lower your blood sugar after meals. It becomes a powerful tool to reverse diabetes. In one study, 15-30 grams (about two to four tablespoons) of potato starch improved insulin sensitivity and fat loss in obese men. 
A separate 2012 study also showed that resistant starch provides cardiovascular benefits. Researchers found adding resistant starch to the diet optimised triglyceride and cholesterol levels while decreasing fat mass. 
Although RS acts like fibre, it is not always found in the same foods. Breakfast cereals like All Brain are high in fibre but contain no RS. RS can be made by cooking and cooling potatoes. The cooling is essential as this will change the cellular structure of the potato to become a resistance stretch. The same cooking and cooling process can turn rice into a RS.
It is possible to buy potato starch in the health food store or online. You can also find resistance starch in seeds, legumes, unripe bananas, unripe plantains, and green peas.
Below is a table of RS foods from highest to lowest per 100g. Some food becomes more RS when cooked and cooled, and others do not. For example potatoes and rice increase RS when cooked and cooled, oats do not.
Fiber and Saturated Fat Are Associated with Sleep Arousals and Slow Wave Sleep. MP, St-Onge, et al. 2012
Resistant starch and “the butyrate revolution”. Browns, F. Et al. 2002
Impact of Dietary Resistant Starch on the Human Gut Microbiome, Metaproteome, and Metabolome. Maier. TV, et al. 2017
The Therapeutic Potential of Resistant Starch in Modulation of Insulin Resistance, Endotoxemia, Oxidative Stress and Antioxidant Biomarkers in Women with Type 2 Diabetes: A Randomized Controlled Clinical Trial. Karimi, P. Et al. 2016
The effect of dietary resistant starch type 2 on the microbiota and markers of gut inflammation in rural Malawi children. Isabel Ordiz, M. Et al. 2015
Resistant starch improves insulin sensitivity in metabolic syndrome. Johnston, KL. Et al. 2010
Dietary resistant starch dose-dependently reduces adiposity in obesity-prone and obesity-resistant male rats. Belobrajdic, DP. Et al. 2012